GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — worker.terminate() during zlib stream construction aborts the process: Assertion failed: init_done_ && "close before init" · Issue #67485 · nodejs/node Done Labels zlibIssues and PRs related to the zlib module and its compression dependencies. DescriptionVersionv22.14.0 (also present in the source of v22.23.5, v24.11, v26.13.1, and main). PlatformSubsystemzlib, worker_threads What steps will reproduce the bug?repro.mjs// Minimal Node repro: terminate() a worker that is busy building zlib streams. One trial = one child process (an abort kills it). // node repro.mjs <trials> <mode: terminate|graceful> <api: zlib|web> import { spawnSync } from 'node:child_process'; import { Worker } from 'node:worker_threads'; const [, , trialsArg = '100', mode = 'terminate', api = 'web', role] = process.argv; const body = api === 'zlib' ? `const zlib = require('node:zlib'); const { parentPort } = require('node:worker_threads'); let stop = false; parentPort.on('message', () => { stop = true; process.exit(0); }); (function loop() { for (let i = 0; i < 200; i++) zlib.createInflateRaw().close(); if (!stop) setImmediate(loop); })();` : `const { parentPort } = require('node:worker_threads'); parentPort.on('message', () => process.exit(0)); const b = new Uint8Array(require('node:zlib').deflateRawSync(Buffer.alloc(4096, 7))); (async function loop() { for (;;) { await Promise.all(Array.from({ length: 8 }, () => new Response(new ReadableStream({ start(c) { c.enqueue(b); c.close(); } }).pipeThrough(new DecompressionStream('deflate-raw'))).arrayBuffer())); } })();`; if (role === 'child') { const w = new Worker(body, { eval: true }); await new Promise((r) => setTimeout(r, 20 + Math.random() * 60)); if (mode === 'terminate') await w.terminate(); else { const exited = new Promise((r) => w.once('exit', r)); w.postMessage('close'); await exited; } process.exit(0); } else { let aborts = 0, other = 0; for (let i = 0; i < Number(trialsArg); i++) { const r = spawnSync(process.execPath, [new URL(import.meta.url).pathname, '1', mode, api, 'child'], { encoding: 'utf8' }); if (r.signal === 'SIGABRT') { aborts++; if (aborts === 1) console.error(r.stderr.split('\n').filter((l) => /Assert|FATAL|close before/.test(l)).slice(0, 3).join('\n')); } else if (r.status !== 0) { other++; console.error('other', r.status, r.signal, r.stderr.slice(0, 300)); } } console.log(JSON.stringify({ node: process.version, mode, api, trials: Number(trialsArg), aborts, other })); } How often does it reproduce? Is there a required condition?The issue is intermittent. On our machine:
What is the expected behavior? Why is that the expected behavior?worker.terminate() should stop the worker without aborting the entire process. Terminating a worker at an arbitrary point is documented and supported behavior. What do you see instead?The parent process terminates with SIGABRT: Assertion failed: init_done_ && "close before init" Additional informationOur understanding of the cause is that zlib stream handles are constructed in two steps in lib/zlib.js:
A possible fix would be to make Close() tolerate an uninitialized handle during environment teardown, releasing it without triggering the assertion, or to make construction and initialization atomic from the JavaScript side. As a workaround, we currently close workers by sending them a message and awaiting their 'exit' event instead of calling terminate(). I'd be happy to submit a fix if the proposed approach makes sense. Activity
MetadataMetadataAssigneesLabelszlibIssues and PRs related to the zlib module and its compression dependencies. TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |