File tree Expand file tree Collapse file tree 5 files changed +63
-11
lines changed
references/hello-world/src/trigger Expand file tree Collapse file tree 5 files changed +63
-11
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " trigger.dev " : patch
3
+ ---
4
+
5
+ Fixes a bug that would allow processes that had OOM errors to be incorrectly reused when experimental_processKeepAlive was enabled
Original file line number Diff line number Diff line change @@ -208,10 +208,18 @@ export class TaskRunProcessPool {
208
208
209
209
private isProcessHealthy ( process : TaskRunProcess ) : boolean {
210
210
// Basic health checks - we can expand this later
211
- return ! process . isBeingKilled && process . pid !== undefined ;
211
+ return process . isHealthy ;
212
212
}
213
213
214
214
private async killProcess ( process : TaskRunProcess ) : Promise < void > {
215
+ if ( ! process . isHealthy ) {
216
+ logger . debug ( "[TaskRunProcessPool] Process is not healthy, skipping cleanup" , {
217
+ processId : process . pid ,
218
+ } ) ;
219
+
220
+ return ;
221
+ }
222
+
215
223
try {
216
224
await process . cleanup ( true ) ;
217
225
} catch ( error ) {
Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ export class TaskRunProcessProvider {
135
135
this . sendDebugLog ( "Not keeping TaskRunProcess alive, cleaning up" , {
136
136
executionCount : this . executionCount ,
137
137
maxExecutionCount : this . processKeepAliveMaxExecutionCount ,
138
- isHealthy : this . isProcessHealthy ( process ) ,
138
+ isHealthy : process . isHealthy ,
139
139
} ) ;
140
140
141
141
// Cleanup the process completely
@@ -284,19 +284,12 @@ export class TaskRunProcessProvider {
284
284
return (
285
285
! ! this . persistentProcess &&
286
286
this . executionCount < this . processKeepAliveMaxExecutionCount &&
287
- this . isProcessHealthy ( this . persistentProcess )
287
+ this . persistentProcess . isHealthy
288
288
) ;
289
289
}
290
290
291
291
private shouldKeepProcessAlive ( process : TaskRunProcess ) : boolean {
292
- return (
293
- this . executionCount < this . processKeepAliveMaxExecutionCount && this . isProcessHealthy ( process )
294
- ) ;
295
- }
296
-
297
- private isProcessHealthy ( process : TaskRunProcess ) : boolean {
298
- // Basic health check - TaskRunProcess will handle more detailed internal health checks
299
- return ! process . isBeingKilled && process . pid !== undefined ;
292
+ return this . executionCount < this . processKeepAliveMaxExecutionCount && process . isHealthy ;
300
293
}
301
294
302
295
private async cleanupProcess ( taskRunProcess : TaskRunProcess ) : Promise < void > {
Original file line number Diff line number Diff line change @@ -442,10 +442,26 @@ export class TaskRunProcess {
442
442
return this . _isBeingKilled || this . _child ?. killed ;
443
443
}
444
444
445
+ get isBeingSuspended ( ) {
446
+ return this . _isBeingSuspended ;
447
+ }
448
+
445
449
get pid ( ) {
446
450
return this . _childPid ;
447
451
}
448
452
453
+ get isHealthy ( ) {
454
+ if ( ! this . _child ) {
455
+ return false ;
456
+ }
457
+
458
+ if ( this . isBeingKilled || this . isBeingSuspended ) {
459
+ return false ;
460
+ }
461
+
462
+ return this . _child . connected ;
463
+ }
464
+
449
465
static parseExecuteError ( error : unknown , dockerMode = true ) : TaskRunInternalError {
450
466
if ( error instanceof CancelledProcessError ) {
451
467
return {
Original file line number Diff line number Diff line change @@ -55,3 +55,33 @@ export const oomTask = task({
55
55
}
56
56
} ,
57
57
} ) ;
58
+
59
+ export const oomTask2 = task ( {
60
+ id : "oom-task-2" ,
61
+ machine : "micro" ,
62
+ run : async ( payload : any , { ctx } ) => {
63
+ await runMemoryLeakScenario ( ) ;
64
+ } ,
65
+ } ) ;
66
+
67
+ async function runMemoryLeakScenario ( ) {
68
+ console . log ( "🧠 Starting memory leak simulation" ) ;
69
+ const memoryHogs = [ ] ;
70
+ let iteration = 0 ;
71
+
72
+ while ( iteration < 1000 ) {
73
+ // Allocate large chunks of memory
74
+ const bigArray = new Array ( 10000000 ) . fill ( `memory-leak-data-${ iteration } ` ) ;
75
+ memoryHogs . push ( bigArray ) ;
76
+
77
+ await setTimeout ( 200 ) ;
78
+ iteration ++ ;
79
+
80
+ const memUsage = process . memoryUsage ( ) ;
81
+ console . log (
82
+ `🧠 Memory leak iteration ${ iteration } , RSS: ${ Math . round ( memUsage . rss / 1024 / 1024 ) } MB`
83
+ ) ;
84
+ }
85
+
86
+ console . log ( "🧠 Memory leak scenario completed" ) ;
87
+ }
You can’t perform that action at this time.
0 commit comments