Skip to content

zlib: handle close before initialization - #67507

Open
ADITHYAKUMARREDDY wants to merge 1 commit into
nodejs:mainfrom
ADITHYAKUMARREDDY:fix/zlib-worker-terminate-init
Open

ADITHYAKUMARREDDY wants to merge 1 commit into
nodejs:mainfrom
ADITHYAKUMARREDDY:fix/zlib-worker-terminate-init

Conversation

@ADITHYAKUMARREDDY

Copy link
Copy Markdown
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

zlib, worker_threads

Description of change

When a worker thread is terminated via worker.terminate() during compression stream construction, execution halts after the native ZlibStream instance has been allocated (new binding.Zlib(mode)) but before handle.init(...) has been executed. As a result, the C++ object has init_done_ == false.

During isolate teardown (node::FreeEnvironment), the garbage collector / weak callback invokes the destructor ~CompressionStream(), which calls Close(). Previously, Close() asserted:

CHECK(init_done_ && "close before init");

Because CHECK() calls abort(), the entire Node.js runtime process crashed with an uncatchable native abort.

The underlying context classes (ZlibContext, BrotliContext, ZstdContext) already safely handle uninitialized destruction. This PR:

  1. Replaces the fatal assertion with a safe early return in CompressionStream::Close() when !init_done_, allowing uninitialized handles to close cleanly.
  2. Adds a regression test in test/parallel/test-zlib-worker-terminate-stream-construct.js asserting that the process does not abort.

Fixes: #67485

Fixes nodejs#67485

Signed-off-by: Adithya kumar Reddy Gopavaram <91198686+ADITHYAKUMARREDDY@users.noreply.github.com>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. zlib Issues and PRs related to the zlib module and its compression dependencies. labels Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

@ADITHYAKUMARREDDY
ADITHYAKUMARREDDY marked this pull request as ready for review November 16, 2026 03:57

@ADITHYAKUMARREDDY ADITHYAKUMARREDDY left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. zlib Issues and PRs related to the zlib module and its compression dependencies.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

worker.terminate() during zlib stream construction aborts the process: Assertion failed: init_done_ && "close before init"

2 participants