Skip to content

fix(model): invalidate channel cache after status update#2392

Open
hobostay wants to merge 1 commit into
songquanpeng:mainfrom
hobostay:fix/channel-cache-invalidation
Open

fix(model): invalidate channel cache after status update#2392
hobostay wants to merge 1 commit into
songquanpeng:mainfrom
hobostay:fix/channel-cache-invalidation

Conversation

@hobostay

Copy link
Copy Markdown

Summary

  • Call InitChannelCache() inside UpdateChannelStatusById() when memory cache is enabled.

Bug

UpdateChannelStatusById() in model/channel.go updates the channel status in the database but does not invalidate the in-memory channel cache (group2model2channels). When MemoryCacheEnabled is true, the stale cache means:

  • Disabled channels continue to receive traffic until the next SyncChannelCache() cycle (default 600 seconds)
  • Auto-recovered channels remain invisible to routing for up to 10 minutes

This affects DisableChannel(), MetricDisableChannel(), and EnableChannel() in monitor/channel.go, which all call UpdateChannelStatusById().

Fix

After a successful database update, call InitChannelCache() to immediately refresh the in-memory cache so routing reflects the new channel status.

Related: #2309

Test plan

  • Enable MEMORY_CACHE_ENABLED=true
  • Create a channel, verify it receives traffic
  • Disable the channel via the admin UI, verify it immediately stops receiving traffic (previously took up to 600s)
  • Re-enable the channel, verify it immediately starts receiving traffic again
  • Run go vet ./model/ to confirm no issues

🤖 Generated with Claude Code

UpdateChannelStatusById() updates the database but does not refresh
the in-memory channel cache (group2model2channels). When
MemoryCacheEnabled is true, the stale cache means disabled channels
continue to receive traffic until the next SyncChannelCache cycle
(default 600 seconds).

Call InitChannelCache() after a successful status update to ensure
the cache is immediately consistent with the database.

Related: songquanpeng#2309

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant