Skip to content

Fix premium tier cache writes failing with context canceled - #13

Open
biast12 wants to merge 1 commit into
masterfrom
fix-premium-tier-cache
Open

biast12 wants to merge 1 commit into
masterfrom
fix-premium-tier-cache

Conversation

@biast12

@biast12 biast12 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Description

GetTierByGuild and GetTierByUserWithSource cache their result in Redis from a goroutine that used the caller's ctx. Callers such as the worker's message listener cancel that ctx as soon as the lookup returns, so the write usually failed with context canceled before reaching Redis and results from those lookups were rarely cached.

  • Cache writes now go through a new cacheTier helper with its own context.Background() and a 3s timeout, like workflowbus/producer.go.
  • Nothing is cached if ctx is already done when the lookup returns. The database module's ListGuildSubscriptions/ListUserSubscriptions don't check rows.Err(), so a query cut short by ctx returns no rows and no error, which would cache a false None for 5 min.

Side effect: these lookups now fill the 5-min cache too, so a new purchase can take up to 5 min longer to be picked up.
Takes effect once worker and dashboard bump common.

Type of Change

  • Bug fix
  • New feature
  • Breaking change

Checklist

  • My code follows the style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Avoid caching incomplete lookups when the request context is canceled, and perform asynchronous cache writes with an independent three-second timeout.
@biast12
biast12 requested a review from a team as a code owner October 7, 2026 18:05
@github-actions github-actions Bot added the type:bug Bug Fixes label Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant