Commit 8d49cff
authored
fix(sdk): fix race condition when checkpoint completion happens before waitForStatusChange is called (#395)
*Issue #, if available:*
*Description of changes:*
There is a race condition in waitForStatusChange where if the operation
completes before this is called, it will not get the status and just
terminate without updating the data correctly. This results in the error
`Cannot return PENDING status with no pending operations.`
To fix this, if the operation status is terminal in waitForStatusChange
or waitForRetryTimer, we resolve instantly instead of creating a promise
and waiting.
This can happen since waitForStatusChange is called asynchronously, so
there can be time between when the phase 2 promise starts and when the
last checkpoint data was updated. I disabled time skipping in
wait-for-callback-serdes.test.ts which consistently shows this (when
running locally). In the cloud tests it's harder to reproduce since we
poll for the callback ID every second and we don't get the data
instantly, but it could still happen in rare cases.
I also added this same safeguard for waitForRetryTimer. This could
happen if the main thread is blocked for a long time somehow and it
fails to call waitForRetryTimer in time.
By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.1 parent f161141 commit 8d49cff
File tree
4 files changed
+538
-0
lines changed- packages
- aws-durable-execution-sdk-js-examples/src/examples/wait-for-callback/quick-completion
- aws-durable-execution-sdk-js/src/utils/checkpoint
4 files changed
+538
-0
lines changedLines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
0 commit comments