From 68849159b1893f40fa795f4785b389a647ae94cf Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 3 Aug 2026 14:26:14 +0000 Subject: [PATCH] docs: prevent write-after-end crash in `repl/presentation` example The nightly `random_examples` workflow crashed running this example in CI: `Error: write after end` at `Presentation.show` (lib/main.js), called from the example's `next()` timeout callback. The example drives an automated slide show via a recursive `setTimeout( next, 2000 )` chain. In a non-interactive CI environment, stdin hits EOF almost immediately, so the REPL emits `exit` well before the slide show would naturally finish. The already-scheduled `next()` timeout still fires afterward and calls `pres.next().show()`, which writes to the REPL's output stream after it has already ended, throwing an unhandled error that crashes the process. This commit tracks the pending timeout in a `timer` variable and clears it in the `exit` handler, so no further slide writes are attempted once the REPL has closed, whether via reaching the last slide or via early stdin EOF. Ref: https://github.com/stdlib-js/stdlib/actions/runs/30775007749 --- .../@stdlib/repl/presentation/examples/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/presentation/examples/index.js b/lib/node_modules/@stdlib/repl/presentation/examples/index.js index f74db49e0416..555526d031a6 100644 --- a/lib/node_modules/@stdlib/repl/presentation/examples/index.js +++ b/lib/node_modules/@stdlib/repl/presentation/examples/index.js @@ -22,7 +22,11 @@ var join = require( 'path' ).join; var REPL = require( '@stdlib/repl' ); var Presentation = require( './../lib' ); // eslint-disable-line stdlib/no-redeclare +var timer; + function onExit() { + // Cancel any pending slide timeout: + clearTimeout( timer ); console.log( '' ); console.log( 'REPL closed.' ); } @@ -46,7 +50,7 @@ var len = pres.length; pres.show(); // Automate the slide show: -setTimeout( next, 2000 ); +timer = setTimeout( next, 2000 ); function next() { // If we are finished with the slide show, close the REPL... @@ -54,5 +58,5 @@ function next() { return repl.close(); } pres.next().show(); - setTimeout( next, 2000 ); + timer = setTimeout( next, 2000 ); }