@sayknow-cli/utils 0.5.1 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/postmortem.ts +17 -4
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@sayknow-cli/utils",
4
- "version": "0.5.1",
4
+ "version": "0.5.4",
5
5
  "description": "Shared utilities for pi packages",
6
6
  "homepage": "https://sayknow-cli.com",
7
7
  "author": "jaybeyond",
@@ -31,7 +31,7 @@
31
31
  "fmt": "biome format --write ."
32
32
  },
33
33
  "dependencies": {
34
- "@sayknow-cli/natives": "0.5.1",
34
+ "@sayknow-cli/natives": "0.5.4",
35
35
  "beautiful-mermaid": "^1.1.3",
36
36
  "handlebars": "^4.7.9",
37
37
  "winston": "^3.19.0",
package/src/postmortem.ts CHANGED
@@ -335,12 +335,25 @@ async function exitQuietlyForAttributableStdoutEpipe(reason: Reason): Promise<vo
335
335
  if (process.exitCode === BROKEN_PIPE_EXIT_CODE) process.exit(BROKEN_PIPE_EXIT_CODE);
336
336
  }
337
337
 
338
+ /**
339
+ * A benign shutdown write error means the sink is already dying, so routing a
340
+ * diagnostic through the logger can hit that same sink and raise the next
341
+ * identical fatal. Latching the note to one attempt per process bounds that:
342
+ * without it, a stdout EPIPE during cleanup drives an unbounded
343
+ * fatal -> log -> fatal loop that pins a core and grows the heap without limit
344
+ * instead of letting the process exit.
345
+ */
346
+ let benignShutdownIoErrorNoted = false;
347
+
338
348
  async function handleFatalError(label: string, reason: unknown, cleanupReason: Reason): Promise<void> {
339
349
  if (cleanupStage !== "idle" && isBenignIoWriteError(reason)) {
340
- logger.debug("Ignoring benign terminal I/O write error during shutdown", {
341
- code: (reason as { code?: unknown }).code,
342
- syscall: (reason as { syscall?: unknown }).syscall,
343
- });
350
+ if (!benignShutdownIoErrorNoted) {
351
+ benignShutdownIoErrorNoted = true;
352
+ logger.debug("Ignoring benign terminal I/O write error during shutdown", {
353
+ code: (reason as { code?: unknown }).code,
354
+ syscall: (reason as { syscall?: unknown }).syscall,
355
+ });
356
+ }
344
357
  return;
345
358
  }
346
359
  if (stdoutEpipeClassifier.isAttributableProcessStdoutEpipe(reason)) {