Skip to content

fix: prevent worker process hanging with proper timer cleanup - #13

Merged
ParidelPooya merged 1 commit into
developmentfrom
fix/timer-cleanup-v2
Sep 7, 2025
Merged

ParidelPooya merged 1 commit into
developmentfrom
fix/timer-cleanup-v2

Conversation

@ParidelPooya

Copy link
Copy Markdown
Contributor

fix: prevent worker process hanging with proper timer cleanup

Fixes 'A worker process has failed to exit gracefully' error by ensuring all setTimeout timers are properly cleaned up.

Root Cause:

- waitBeforeContinue creates multiple polling timers via setTimeout
- Promise.race resolves when any condition is met
- Remaining timers from unresolved promises kept running
- Jest worker processes couldn't exit due to active handles

Solution:

- Track all setTimeout timers in arrays
- Clear all timers after Promise.race resolves
- Add proper cleanup in both implementation and tests
- Prevent resource leaks and hanging processes

Changes:

- waitBeforeContinue: Track and cleanup timers after Promise.race
- Tests: Track test timers and clear in afterEach hooks
- Eliminates worker process hanging warnings
- Ensures proper resource management in production

Fixes 'A worker process has failed to exit gracefully' error by ensuring
all setTimeout timers are properly cleaned up.

## Root Cause:
- waitBeforeContinue creates multiple polling timers via setTimeout
- Promise.race resolves when any condition is met
- Remaining timers from unresolved promises kept running
- Jest worker processes couldn't exit due to active handles

## Solution:
- Track all setTimeout timers in arrays
- Clear all timers after Promise.race resolves
- Add proper cleanup in both implementation and tests
- Prevent resource leaks and hanging processes

## Changes:
- waitBeforeContinue: Track and cleanup timers after Promise.race
- Tests: Track test timers and clear in afterEach hooks
- Eliminates worker process hanging warnings
- Ensures proper resource management in production
@ParidelPooya
ParidelPooya merged commit 8b20711 into development Sep 7, 2025
1 check passed
@ParidelPooya
ParidelPooya deleted the fix/timer-cleanup-v2 branch September 7, 2025 01:28
ParidelPooya added a commit that referenced this pull request Oct 10, 2025
fix: prevent worker process hanging with proper timer cleanup
    
Fixes 'A worker process has failed to exit gracefully' error by ensuring
all setTimeout timers are properly cleaned up.
    
## Root Cause:
    - waitBeforeContinue creates multiple polling timers via setTimeout
    - Promise.race resolves when any condition is met
    - Remaining timers from unresolved promises kept running
    - Jest worker processes couldn't exit due to active handles
    
## Solution:
    - Track all setTimeout timers in arrays
    - Clear all timers after Promise.race resolves
    - Add proper cleanup in both implementation and tests
    - Prevent resource leaks and hanging processes
    
## Changes:
    - waitBeforeContinue: Track and cleanup timers after Promise.race
    - Tests: Track test timers and clear in afterEach hooks
    - Eliminates worker process hanging warnings
    - Ensures proper resource management in production

Co-authored-by: Pooya Paridel <parpooya@amazon.com>
ParidelPooya added a commit that referenced this pull request Oct 12, 2025
fix: prevent worker process hanging with proper timer cleanup
    
Fixes 'A worker process has failed to exit gracefully' error by ensuring
all setTimeout timers are properly cleaned up.
    
## Root Cause:
    - waitBeforeContinue creates multiple polling timers via setTimeout
    - Promise.race resolves when any condition is met
    - Remaining timers from unresolved promises kept running
    - Jest worker processes couldn't exit due to active handles
    
## Solution:
    - Track all setTimeout timers in arrays
    - Clear all timers after Promise.race resolves
    - Add proper cleanup in both implementation and tests
    - Prevent resource leaks and hanging processes
    
## Changes:
    - waitBeforeContinue: Track and cleanup timers after Promise.race
    - Tests: Track test timers and clear in afterEach hooks
    - Eliminates worker process hanging warnings
    - Ensures proper resource management in production

Co-authored-by: Pooya Paridel <parpooya@amazon.com>
ParidelPooya added a commit that referenced this pull request Oct 24, 2025
fix: prevent worker process hanging with proper timer cleanup
    
Fixes 'A worker process has failed to exit gracefully' error by ensuring
all setTimeout timers are properly cleaned up.
    
## Root Cause:
    - waitBeforeContinue creates multiple polling timers via setTimeout
    - Promise.race resolves when any condition is met
    - Remaining timers from unresolved promises kept running
    - Jest worker processes couldn't exit due to active handles
    
## Solution:
    - Track all setTimeout timers in arrays
    - Clear all timers after Promise.race resolves
    - Add proper cleanup in both implementation and tests
    - Prevent resource leaks and hanging processes
    
## Changes:
    - waitBeforeContinue: Track and cleanup timers after Promise.race
    - Tests: Track test timers and clear in afterEach hooks
    - Eliminates worker process hanging warnings
    - Ensures proper resource management in production

Co-authored-by: Pooya Paridel <parpooya@amazon.com>
ParidelPooya added a commit that referenced this pull request Oct 26, 2025
fix: prevent worker process hanging with proper timer cleanup
    
Fixes 'A worker process has failed to exit gracefully' error by ensuring
all setTimeout timers are properly cleaned up.
    
## Root Cause:
    - waitBeforeContinue creates multiple polling timers via setTimeout
    - Promise.race resolves when any condition is met
    - Remaining timers from unresolved promises kept running
    - Jest worker processes couldn't exit due to active handles
    
## Solution:
    - Track all setTimeout timers in arrays
    - Clear all timers after Promise.race resolves
    - Add proper cleanup in both implementation and tests
    - Prevent resource leaks and hanging processes
    
## Changes:
    - waitBeforeContinue: Track and cleanup timers after Promise.race
    - Tests: Track test timers and clear in afterEach hooks
    - Eliminates worker process hanging warnings
    - Ensures proper resource management in production

Co-authored-by: Pooya Paridel <parpooya@amazon.com>
ParidelPooya added a commit that referenced this pull request Nov 2, 2025
fix: prevent worker process hanging with proper timer cleanup
    
Fixes 'A worker process has failed to exit gracefully' error by ensuring
all setTimeout timers are properly cleaned up.
    
## Root Cause:
    - waitBeforeContinue creates multiple polling timers via setTimeout
    - Promise.race resolves when any condition is met
    - Remaining timers from unresolved promises kept running
    - Jest worker processes couldn't exit due to active handles
    
## Solution:
    - Track all setTimeout timers in arrays
    - Clear all timers after Promise.race resolves
    - Add proper cleanup in both implementation and tests
    - Prevent resource leaks and hanging processes
    
## Changes:
    - waitBeforeContinue: Track and cleanup timers after Promise.race
    - Tests: Track test timers and clear in afterEach hooks
    - Eliminates worker process hanging warnings
    - Ensures proper resource management in production

Co-authored-by: Pooya Paridel <parpooya@amazon.com>
ParidelPooya added a commit that referenced this pull request Nov 6, 2025
fix: prevent worker process hanging with proper timer cleanup
    
Fixes 'A worker process has failed to exit gracefully' error by ensuring
all setTimeout timers are properly cleaned up.
    
## Root Cause:
    - waitBeforeContinue creates multiple polling timers via setTimeout
    - Promise.race resolves when any condition is met
    - Remaining timers from unresolved promises kept running
    - Jest worker processes couldn't exit due to active handles
    
## Solution:
    - Track all setTimeout timers in arrays
    - Clear all timers after Promise.race resolves
    - Add proper cleanup in both implementation and tests
    - Prevent resource leaks and hanging processes
    
## Changes:
    - waitBeforeContinue: Track and cleanup timers after Promise.race
    - Tests: Track test timers and clear in afterEach hooks
    - Eliminates worker process hanging warnings
    - Ensures proper resource management in production

Co-authored-by: Pooya Paridel <parpooya@amazon.com>
ParidelPooya added a commit that referenced this pull request Nov 6, 2025
fix: prevent worker process hanging with proper timer cleanup
    
Fixes 'A worker process has failed to exit gracefully' error by ensuring
all setTimeout timers are properly cleaned up.
    
## Root Cause:
    - waitBeforeContinue creates multiple polling timers via setTimeout
    - Promise.race resolves when any condition is met
    - Remaining timers from unresolved promises kept running
    - Jest worker processes couldn't exit due to active handles
    
## Solution:
    - Track all setTimeout timers in arrays
    - Clear all timers after Promise.race resolves
    - Add proper cleanup in both implementation and tests
    - Prevent resource leaks and hanging processes
    
## Changes:
    - waitBeforeContinue: Track and cleanup timers after Promise.race
    - Tests: Track test timers and clear in afterEach hooks
    - Eliminates worker process hanging warnings
    - Ensures proper resource management in production

Co-authored-by: Pooya Paridel <parpooya@amazon.com>
ParidelPooya added a commit that referenced this pull request Nov 6, 2025
fix: prevent worker process hanging with proper timer cleanup
    
Fixes 'A worker process has failed to exit gracefully' error by ensuring
all setTimeout timers are properly cleaned up.
    
## Root Cause:
    - waitBeforeContinue creates multiple polling timers via setTimeout
    - Promise.race resolves when any condition is met
    - Remaining timers from unresolved promises kept running
    - Jest worker processes couldn't exit due to active handles
    
## Solution:
    - Track all setTimeout timers in arrays
    - Clear all timers after Promise.race resolves
    - Add proper cleanup in both implementation and tests
    - Prevent resource leaks and hanging processes
    
## Changes:
    - waitBeforeContinue: Track and cleanup timers after Promise.race
    - Tests: Track test timers and clear in afterEach hooks
    - Eliminates worker process hanging warnings
    - Ensures proper resource management in production

Co-authored-by: Pooya Paridel <parpooya@amazon.com>
ParidelPooya added a commit that referenced this pull request Nov 7, 2025
fix: prevent worker process hanging with proper timer cleanup
    
Fixes 'A worker process has failed to exit gracefully' error by ensuring
all setTimeout timers are properly cleaned up.
    
## Root Cause:
    - waitBeforeContinue creates multiple polling timers via setTimeout
    - Promise.race resolves when any condition is met
    - Remaining timers from unresolved promises kept running
    - Jest worker processes couldn't exit due to active handles
    
## Solution:
    - Track all setTimeout timers in arrays
    - Clear all timers after Promise.race resolves
    - Add proper cleanup in both implementation and tests
    - Prevent resource leaks and hanging processes
    
## Changes:
    - waitBeforeContinue: Track and cleanup timers after Promise.race
    - Tests: Track test timers and clear in afterEach hooks
    - Eliminates worker process hanging warnings
    - Ensures proper resource management in production

Co-authored-by: Pooya Paridel <parpooya@amazon.com>
ParidelPooya added a commit that referenced this pull request Aug 2, 2026
Review items 7, 8, 9, 10, 13.

#7 The update path only ever sent DurableConfig, so Runtime/Handler/Timeout/
MemorySize were set exclusively in the create branch. Redeploying onto a
pre-existing function replaced its code with ours while leaving it on whatever
runtime and handler it already had — the generated bundle needs this runtime and
index.handler, so it failed at invoke for a reason the deploy output never
explained. Update now converges the same shape a create produces. Role is
deliberately NOT repointed: it may be user-managed, and silently changing it is
destructive in a way a code update is not.

PutRolePolicy also guessed `${functionName}-role`, which is only correct when we
created the role in the same run. On the update path ensureExecutionRole never
runs, so the guess could name a nonexistent role (swallowed) or an unrelated one
that matched the pattern. It now resolves the function's effective role from
GetFunctionConfiguration and derives the name from that ARN (last path segment,
since role ARNs may carry a path).

#8 Confirmed and it is the worst of these: Succeed and Fail both mapped to a bare
end node, and with no endMode codegen emits a return — so EVERY imported Fail
reported the execution as SUCCEEDED. Error and Cause were dropped, so the reason
disappeared too. Fail now emits endMode "throw" carrying Error and Cause.
aslImport.test.ts asserted the old shape and has been corrected.

#9 One correction: the join is NOT the bug. Codegen already splits a
comma-separated errorType and ORs the instanceof checks, so
["States.Timeout","States.ALL"] produced two separate checks, not one bad string.
The real defect is that ASL error NAMES are not JavaScript classes, so
`err instanceof States.Timeout` is a ReferenceError at runtime, and States.ALL is
a catch-all rather than a type. Now: States.ALL becomes a genuine catch-all,
other States.* names are dropped with a note, and non-States names are kept since
a custom ASL error name plausibly is the thrown class.

#10 Agreed this is the largest ASL gap. InputPath/OutputPath/ResultPath/
ResultSelector were declared and never read, with no note — an import could look
right on the canvas and route data completely differently. Translating JSONPath
data-flow is not a small change and guessing would be worse, but dropping it
SILENTLY is the indefensible part, so every dropped field is now reported, plus
TimeoutSeconds/HeartbeatSeconds (which were not even declared), JSONata
QueryLanguage, and Retry/Catch on non-Task states.

#13 grantInferredPermissions defaulted to true with resources: ["*"]. Split it:
statements with resolvable resources (chainInvoke targets) are still granted, and
wildcard statements are withheld and reported as a CDK warning naming the exact
actions. New grantWildcardPermissions opt-in restores the old behaviour. A
construct should not hand out wildcard access off a regex match.

22 new tests. cdk 257, insight-vscode 413, all green.
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