Skip to content

[4.1.3 Backport] CBG-5874: prevent async index init panic with concurrent GET - #8894

Merged
torcolvin merged 1 commit into
release/4.1.3from
CBG-5874
Oct 23, 2026
Merged

torcolvin merged 1 commit into
release/4.1.3from
CBG-5874

Conversation

@vipbhardwaj

@vipbhardwaj vipbhardwaj commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

CBG-5874 (backport of CBG-5869)

A GET of _index_init while index initialisation was running could crash Sync Gateway: the status map was marshalled while the init worker was still writing to it. Status now lives in an IndexStatusTracker that is written and copied under its own lock.

Unclean cherry pick of #8806 to 4.1.3
Adapted to 4.1.3 without CBG-5653 (typed background manager options), per team advice.
Changes from main commit:

  • db/background_mgr_async_index_init.go, rest/admin_api.go — main passes the tracker in the typed AsyncIndexInitOptions from CBG-5653; 4.1.3 still uses map[string]any options, so it is passed as options["statusTracker"].(*IndexStatusTracker). The race fix itself is as upstream
  • db/background_mgr_async_index_init_test.go — Init takes map options to match; release branch predates the testing/{require,assert} wrappers, so imports renamed back to testify

🤖 Opened with the sync-gateway-backport skill in Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The locking, snapshot copying, and backport wiring address the race without identified blocking issues; tests were not executed.

0 open findings

What changed in this PR

Backports the concurrent _index_init status-read fix to Sync Gateway 4.1.3, retaining the release branch’s map-based options.

Changes:

  • Protects status updates and snapshot copying with a dedicated tracker lock.
  • Wires the tracker into the REST handler and background manager lifecycle.
  • Adds a concurrent status-update/read regression test.
File Description
rest/​admin_api.go Creates and passes the tracker; routes status updates through it.
db/​background_mgr_async_index_init.go Adds synchronized status tracking and independent snapshots.
db/​background_mgr_async_index_init_test.go Tests concurrent status writes and reads.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…rent GET

Cherry-picked from d81f862 (CBG-5869, #8806), adapted to 4.1.3 without
CBG-5653 (typed background manager options), per team advice.
- db/background_mgr_async_index_init.go, rest/admin_api.go: main passes
  the status tracker in the typed AsyncIndexInitOptions from CBG-5653;
  4.1.3 still uses map[string]any options, so the tracker is passed as
  options["statusTracker"].(*IndexStatusTracker). The race fix itself
  (IndexStatusTracker and copying status under its lock) is as upstream.
- db/background_mgr_async_index_init_test.go: Init takes map options to
  match; imports renamed from the testing/{require,assert} wrappers to
  testify, which 4.1.3 uses.

Co-authored-by: Tor Colvin <tor.colvin@couchbase.com>
@torcolvin
torcolvin removed this pull request from stack #8895 October 22, 2026 14:22
@torcolvin
torcolvin changed the base branch from CBG-5913 to release/4.1.3 October 22, 2026 14:23
@torcolvin
torcolvin enabled auto-merge (squash) October 23, 2026 14:41
@torcolvin
torcolvin disabled auto-merge October 23, 2026 14:41
@torcolvin
torcolvin merged commit 199436b into release/4.1.3 Oct 23, 2026
43 checks passed
@torcolvin
torcolvin deleted the CBG-5874 branch October 23, 2026 14:41
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.

3 participants