Skip to content

Ensure worker re-initializes after startup failure - #1804

Merged
ehasah-aws merged 5 commits into
awslabs:masterfrom
ehasah-aws:migration-state-machine-init-retry
Sep 4, 2026
Merged

ehasah-aws merged 5 commits into
awslabs:masterfrom
ehasah-aws:migration-state-machine-init-retry

Conversation

@ehasah-aws

@ehasah-aws ehasah-aws commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

  • Fix initialization guard so retries actually re-initialize after a transient failure
  • Prevent duplicate background threads when initialization is retried

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Move startingClientVersion assignment after enter() succeeds in
MigrationStateMachineImpl.initialize(). Previously, startingClientVersion
was set before enter(), so if enter() threw a DependencyException (e.g.
GSI creation timeout), the retry path saw a non-null startingClientVersion
and skipped re-initialization entirely. The worker entered a zombie
state β€” holding and renewing leases but not processing records.

Also add an idempotency guard in initializeStartupComponents() to
prevent duplicate thread creation if the method is called again after
a successful first run. Revert GSI timeout from 3600s workaround to
the original 600s now that the root cause is fixed.

Includes 6 new unit tests covering retry behavior for all client
version paths (3x, upgradeFrom2x, phase1, 3xWithRollback).
// Extending the timeout to a long time to ensure GSI is created as a short term fix and will revisit
// on the proper fix in the future
final long timeoutSeconds = 3600L;
final long timeoutSeconds = 600L;

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.

How long does GSI initialization take? From my testing previously, a 4 shard new application took 15-20 mins to initialize the GSI, so we should probably just set the timeout to longer than that to avoid unnecessary retries. We can reduce it though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just reverted to what we had initially. For me it took about same time 15-20 minutes. I read https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.OnlineOps.html, GSI creation time depends on few factors like size of table, number of items in the table, etc.
I agree with your point though. I will change it back to 3600L

startingState.enter(ClientVersion.CLIENT_VERSION_INIT);

// Only set after enter() succeeds β€” this is the guard that prevents
// double-initialization. Setting it before enter() caused the zombie bug.

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.

Do we need the second sentence comment?

@ehasah-aws ehasah-aws Sep 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can clean the comment

@ehasah-aws ehasah-aws changed the title Ensure worker re-initializes after transient startup failure Ensure worker re-initializes after startup failure Sep 3, 2026
@ehasah-aws
ehasah-aws deployed to manual-approval September 4, 2026 00:03 — with GitHub Actions Active
@ehasah-aws
ehasah-aws merged commit f27aa42 into awslabs:master Sep 4, 2026
5 checks passed

This branch was successfully deployed

1 active deployment
manual-approval β€” 05e261b3 Deployed Sep 4, 2026 by ehasah-aws via wait-for-approval #300
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.

2 participants