Skip to content

[4.1.2 Backport] CBG-5743: passing invalid collections to /db/_resync?action=start will cause resync to be stuck in running - #8631

Open
torcolvin wants to merge 1 commit into
release/4.1.2from
CBG-5743
Open

[4.1.2 Backport] CBG-5743: passing invalid collections to /db/_resync?action=start will cause resync to be stuck in running#8631
torcolvin wants to merge 1 commit into
release/4.1.2from
CBG-5743

Conversation

@torcolvin

@torcolvin torcolvin commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

CBG-5743

Unclean cherry pick of #8454 (CBG-5496) to 4.1.2

Stacked on #8660 (CBG-5752), which sits on #8635 (CBG-5744).

Changes from main commit:

  • db/background_mgr_test.goTestBackgroundManagerStartReturnsErrorWhileProcessKeepsRunning is typed against MockProcessOptions, added by CBG-5653 (CBG-5653 switch backgroundmanager options to strong types #8490) which is not on 4.1.2. Applied in full against BackgroundManager[map[string]any], matching the rest of the file on this branch; no assertions changed. The test keeps upstream's t.Skip for CBG-5660.

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

@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown

Redocly previews

@torcolvin
torcolvin marked this pull request as ready for review August 20, 2026 15:14
@torcolvin
torcolvin requested review from a team and a lite review from Copilot August 20, 2026 15:14

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.

Pull request overview

Backports the fix for a Sync Gateway 4.1.2 issue where starting _resync with invalid collection names could leave the resync/background-manager state stuck as running, blocking subsequent resync attempts until manual cleanup.

Changes:

  • Reset database run-state from DBResyncing back to DBOffline when resync start fails, preventing the DB from being left in a resyncing state.
  • Treat invalid collection names as a client error (400 Bad Request) and add an end-to-end REST test to ensure status transitions to error rather than remaining running.
  • Persist terminal background-manager status and clear heartbeat docs via a shared updateTerminalStatus() helper.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rest/api.go Resets h.db.State back to offline when ResyncManager.Start fails.
rest/adminapitest/resync_test.go Adds TestResyncInvalidCollections to cover invalid-collections start behavior and recovery.
docs/api/paths/admin/db-_resync.yaml Documents a 400 response for _resync POST.
db/background_mgr.go Marks synchronous start failures as error and persists terminal status via updateTerminalStatus().
db/background_mgr_resync_dcp.go Converts invalid collection resolution failures into 400 Bad Request.
base/leaky_datastore.go Adds a pre-update test hook to fail before calling the underlying datastore.
base/leaky_bucket.go Plumbs PreUpdateCallback into LeakyBucketConfig with thread-safe accessors.

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

Comment thread db/background_mgr_resync_dcp.go
Comment thread db/background_mgr.go
@bbrks

bbrks commented Aug 25, 2026

Copy link
Copy Markdown
Member

db/background_mgr_test.go — upstream's test additions dropped; they depend on the testing/require and testing/sgtest packages, which do not exist on 4.1.2

again

@bbrks bbrks assigned torcolvin and unassigned bbrks Aug 25, 2026
@torcolvin torcolvin assigned bbrks and unassigned torcolvin Aug 26, 2026
bbrks
bbrks previously approved these changes Aug 26, 2026
Base automatically changed from CBG-5752 to release/4.1.2 August 26, 2026 18:09
…?action=start will cause resync to be stuck in running

Cherry-picked from 2758dbf (CBG-5496, #8454).

Adapted db/background_mgr_test.go: upstream's new
TestBackgroundManagerStartReturnsErrorWhileProcessKeepsRunning is typed against
MockProcessOptions, introduced by CBG-5653 (#8490, "switch backgroundmanager
options to strong types"), which is not on 4.1.2. The test is applied in full
with BackgroundManager[map[string]any] and map[string]any{} options, matching how
every other test in this file instantiates the manager on 4.1.2. No assertions
changed. The test carries upstream's t.Skip for CBG-5660.

Prerequisite for CBG-5594 (CBG-5521): introduces updateTerminalStatus() and the
SetError() call in BackgroundManager.start() that it builds on.

Co-authored-by: Ritesh Sapata <34858159+RIT3shSapata@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 (1M context) <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.

4 participants