Commit c90c09e
fix: prevent worker process hanging with proper timer cleanup (#13)
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>1 parent 871abf5 commit c90c09e
File tree
2 files changed
+26
-6
lines changed- packages/lambda-durable-functions-sdk-js/src/utils/wait-before-continue
2 files changed
+26
-6
lines changedLines changed: 12 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
14 | 22 | | |
15 | 23 | | |
16 | 24 | | |
| |||
28 | 36 | | |
29 | 37 | | |
30 | 38 | | |
31 | | - | |
| 39 | + | |
32 | 40 | | |
33 | 41 | | |
| 42 | + | |
34 | 43 | | |
35 | 44 | | |
36 | 45 | | |
| |||
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
71 | | - | |
| 80 | + | |
72 | 81 | | |
73 | 82 | | |
| 83 | + | |
74 | 84 | | |
75 | 85 | | |
76 | 86 | | |
| |||
Lines changed: 14 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
57 | 63 | | |
58 | 64 | | |
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
63 | | - | |
| 69 | + | |
| 70 | + | |
64 | 71 | | |
65 | 72 | | |
66 | 73 | | |
| |||
75 | 82 | | |
76 | 83 | | |
77 | 84 | | |
78 | | - | |
| 85 | + | |
| 86 | + | |
79 | 87 | | |
80 | 88 | | |
81 | 89 | | |
| |||
92 | 100 | | |
93 | 101 | | |
94 | 102 | | |
95 | | - | |
| 103 | + | |
| 104 | + | |
96 | 105 | | |
97 | 106 | | |
98 | 107 | | |
| |||
105 | 114 | | |
106 | 115 | | |
107 | 116 | | |
108 | | - | |
| 117 | + | |
109 | 118 | | |
| 119 | + | |
110 | 120 | | |
111 | 121 | | |
112 | 122 | | |
| |||
0 commit comments