Conversation
If there are pending events from FireEvent but there are no consumers, the FireEvent will hang when <-cbgt.CbgEvent is called. - Create a Stop method with a cancellable context so that any sends are cancelled - create CfgSGMem which contains a cbgt.CfgMem implementation in Sync Gateway by using a shim that supports either DataStore or a map. The CfgSGMem is the CfgMem implementation. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Droid finished @torcolvin's task —— View job |
There was a problem hiding this comment.
Pull request overview
This PR addresses a goroutine leak/hang scenario in cbgt.Cfg event delivery by making Sync Gateway’s CfgSG event sending cancellable and by replacing the CE cbgt.NewCfgMem usage with an in-repo, stoppable in-memory CfgSG backend.
Changes:
- Introduces a cancellable context +
Stop()onbase.CfgSGto unblock pendingFireEvent/Refreshsends. - Adds an in-memory
cfgMemoryStoragebackend and exposes it viabase.NewCbgtCfgMem(ctx)as a CE replacement forcbgt.NewCfgMem. - Wires
DatabaseContextand tests to use the newCfgSG-based cfg and stop it during shutdown.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| db/database.go | Switches CfgSG to *base.CfgSG, uses new NewCbgtCfgMem(ctx), and stops it on shutdown. |
| base/sg_cluster_cfg.go | Adds cancellable context + Stop(), introduces cfgMemoryStorage, and updates event delivery to be cancel-aware. |
| base/sg_cluster_cfg_test.go | Adds coverage for Get/Set/Del semantics, event delivery, and Stop() unblocking behavior across backends. |
| base/heartbeat_test.go | Updates tests to pass context into NewCbgtCfgMem(ctx). |
| base/dcp_test.go | Updates tests to pass context into NewCbgtCfgMem(ctx). |
| base/cbgt.go | Removes the old cbgt.NewCfgMem wrapper in favor of the new CfgSG-based implementation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
One correctness issue to address: CfgSG.Stop currently does not stop cfgNodePoller because the poller is started with the non-cancellable ctx, so polling goroutines can survive database stop/offline. The other candidate items were test robustness suggestions rather than concrete defects.
CBG-2413: remove memory leak in cbgt.Cfg implementations
If there are pending events from FireEvent but there are no consumers, the FireEvent will hang when <-cbgt.CbgEvent is called.
Pre-review checklist
base.UD(docID),base.MD(dbName))docs/apiIntegration Tests