Skip to content

fix(core): add timeout to BackgroundProcessManager.close()#14719

Open
anivar wants to merge 1 commit intoaws-amplify:mainfrom
anivar:fix/background-process-manager-close-timeout
Open

fix(core): add timeout to BackgroundProcessManager.close()#14719
anivar wants to merge 1 commit intoaws-amplify:mainfrom
anivar:fix/background-process-manager-close-timeout

Conversation

@anivar
Copy link
Contributor

@anivar anivar commented Feb 17, 2026

Description of changes

BackgroundProcessManager.close() awaits Promise.allSettled(jobs) with no timeout. When jobs ignore the onTerminate signal (e.g. the subscription processor has a TODO at subscription.ts:411), close() hangs forever. This causes DataStore to get permanently stuck in "Stopping" state after network drops — every subsequent save/query/start throws DataStoreStateError and only an app restart recovers.

Fix: Race _closingPromise against a 10s timeout so close() always resolves. Key details:

  • Reassigns this._closingPromise to the race result (required because async close() returns it, and callers would otherwise re-block on the original never-settling allSettled)
  • On timeout, logs a warning with pending job descriptions for debuggability
  • Clears this.jobs set after timeout to prevent zombie jobs persisting across close()open() cycles (used by all DataStore sync processors)

Issue #, if available

Related: #13035 #10612 #12359

Description of how you validated changes

  • All 31 BackgroundProcessManager tests pass (including new timeout test)
  • New test verifies: close resolves within 15s, state transitions to Closed, jobs set is cleared, warning is logged with pending job descriptions

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@anivar anivar requested a review from a team as a code owner February 17, 2026 12:23
@changeset-bot
Copy link

changeset-bot bot commented Feb 17, 2026

🦋 Changeset detected

Latest commit: 20b3fb6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@aws-amplify/core Patch
@aws-amplify/api-graphql Patch
@aws-amplify/api Patch
@aws-amplify/datastore Patch
aws-amplify Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@anivar anivar force-pushed the fix/background-process-manager-close-timeout branch from a39a1f8 to 287c576 Compare March 7, 2026 13:06
Race close() against a 10s timeout so it always resolves, even when
jobs ignore the onTerminate signal (e.g. subscription processor).
On timeout, logs a warning with pending job descriptions and clears
the jobs set to prevent zombie jobs persisting across close/open cycles.

Resolves stuck "Stopping" state in DataStore after network drops.

Related: aws-amplify#13035 aws-amplify#10612 aws-amplify#12359
@anivar anivar force-pushed the fix/background-process-manager-close-timeout branch from 287c576 to 20b3fb6 Compare March 7, 2026 13:43
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