Skip to content

Commit 12ad920

Browse files
committed
separate SIGTERM from maybe OOM errors
1 parent 4c8618d commit 12ad920

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

packages/core/src/v3/errors.ts

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,14 @@ const prettyInternalErrors: Partial<
331331
href: links.docs.machines.home,
332332
},
333333
},
334+
TASK_PROCESS_SIGTERM: {
335+
message:
336+
"Your task exited after receiving SIGTERM but we don't know why. If this keeps happening, please get in touch so we can investigate.",
337+
link: {
338+
name: "Contact us",
339+
href: links.site.contact,
340+
},
341+
},
334342
};
335343

336344
type EnhanceError<T extends TaskRunError | ExceptionEventProperties> = T & {
@@ -342,6 +350,14 @@ export function taskRunErrorEnhancer(error: TaskRunError): EnhanceError<TaskRunE
342350
case "BUILT_IN_ERROR": {
343351
if (error.name === "UnexpectedExitError") {
344352
if (error.message.startsWith("Unexpected exit with code -1")) {
353+
if (error.message.includes("SIGTERM")) {
354+
return {
355+
type: "INTERNAL_ERROR",
356+
code: TaskRunErrorCodes.TASK_PROCESS_SIGTERM,
357+
...prettyInternalErrors.TASK_PROCESS_SIGTERM,
358+
};
359+
}
360+
345361
return {
346362
type: "INTERNAL_ERROR",
347363
code: TaskRunErrorCodes.TASK_PROCESS_MAYBE_OOM_KILLED,
@@ -359,6 +375,14 @@ export function taskRunErrorEnhancer(error: TaskRunError): EnhanceError<TaskRunE
359375
}
360376
case "INTERNAL_ERROR": {
361377
if (error.code === TaskRunErrorCodes.TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE) {
378+
if (error.message?.includes("SIGTERM")) {
379+
return {
380+
type: "INTERNAL_ERROR",
381+
code: TaskRunErrorCodes.TASK_PROCESS_SIGTERM,
382+
...prettyInternalErrors.TASK_PROCESS_SIGTERM,
383+
};
384+
}
385+
362386
return {
363387
type: "INTERNAL_ERROR",
364388
code: TaskRunErrorCodes.TASK_PROCESS_MAYBE_OOM_KILLED,
@@ -396,7 +420,8 @@ export function exceptionEventEnhancer(
396420
break;
397421
}
398422
case TaskRunErrorCodes.TASK_PROCESS_MAYBE_OOM_KILLED:
399-
case TaskRunErrorCodes.TASK_PROCESS_OOM_KILLED: {
423+
case TaskRunErrorCodes.TASK_PROCESS_OOM_KILLED:
424+
case TaskRunErrorCodes.TASK_PROCESS_SIGTERM: {
400425
return {
401426
...exception,
402427
...prettyInternalErrors[exception.type],
@@ -411,32 +436,45 @@ export function internalErrorFromUnexpectedExit(
411436
error: UnexpectedExitError,
412437
dockerMode = true
413438
): TaskRunInternalError {
439+
const internalError = {
440+
type: "INTERNAL_ERROR",
441+
code: TaskRunErrorCodes.TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE,
442+
message: `Process exited with code ${error.code} after signal ${error.signal}.`,
443+
stackTrace: error.stderr,
444+
} satisfies TaskRunInternalError;
445+
414446
if (error.code === 137) {
415447
if (dockerMode) {
416448
return {
417-
type: "INTERNAL_ERROR",
449+
...internalError,
418450
code: TaskRunErrorCodes.TASK_PROCESS_OOM_KILLED,
419451
};
420452
} else {
421453
// Note: containerState reason and message could be checked to clarify the error, maybe the task monitor should be allowed to override these
422454
return {
423-
type: "INTERNAL_ERROR",
455+
...internalError,
424456
code: TaskRunErrorCodes.TASK_PROCESS_MAYBE_OOM_KILLED,
425457
};
426458
}
427459
}
428460

429461
if (error.stderr?.includes("OOMErrorHandler")) {
430462
return {
431-
type: "INTERNAL_ERROR",
463+
...internalError,
432464
code: TaskRunErrorCodes.TASK_PROCESS_OOM_KILLED,
433465
};
434466
}
435467

468+
if (error.signal === "SIGTERM") {
469+
return {
470+
...internalError,
471+
code: TaskRunErrorCodes.TASK_PROCESS_SIGTERM,
472+
};
473+
}
474+
436475
return {
437-
type: "INTERNAL_ERROR",
476+
...internalError,
438477
code: TaskRunErrorCodes.TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE,
439-
message: `Process exited with code ${error.code} after signal ${error.signal}.`,
440478
};
441479
}
442480

packages/core/src/v3/schemas/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export const TaskRunErrorCodes = {
8787
TASK_EXECUTION_ABORTED: "TASK_EXECUTION_ABORTED",
8888
TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE: "TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE",
8989
TASK_PROCESS_SIGKILL_TIMEOUT: "TASK_PROCESS_SIGKILL_TIMEOUT",
90+
TASK_PROCESS_SIGTERM: "TASK_PROCESS_SIGTERM",
9091
TASK_PROCESS_OOM_KILLED: "TASK_PROCESS_OOM_KILLED",
9192
TASK_PROCESS_MAYBE_OOM_KILLED: "TASK_PROCESS_MAYBE_OOM_KILLED",
9293
TASK_RUN_CANCELLED: "TASK_RUN_CANCELLED",
@@ -112,6 +113,7 @@ export const TaskRunInternalError = z.object({
112113
"TASK_EXECUTION_ABORTED",
113114
"TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE",
114115
"TASK_PROCESS_SIGKILL_TIMEOUT",
116+
"TASK_PROCESS_SIGTERM",
115117
"TASK_PROCESS_OOM_KILLED",
116118
"TASK_PROCESS_MAYBE_OOM_KILLED",
117119
"TASK_RUN_CANCELLED",

0 commit comments

Comments
 (0)