Skip to content

zlib: prevent concurrent parameter changes - #67609

Open
ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:zlib-ordered-params
Open

ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:zlib-ordered-params

Conversation

@ShogunPanda

Copy link
Copy Markdown
Contributor

zlib.params() only deferred the parameter change behind a flush. When writes were queued behind that flush, the next write could be dispatched to the threadpool before the parameters were applied on the main thread, so deflateParams() and deflate() could run concurrently on the same z_stream.

Parameter changes are now applied as an ordered operation before the next queued write starts, and the native params() binding throws if a write is in progress, like reset() already does. A change that is still pending when the stream is destroyed or errors is not applied. Consecutive params() calls are compared against the last requested values, so a change back to the original values is no longer skipped.

Adds regression tests for the public API race, the native guard, a parameter change with no following write, flush/params/write ordering and destroying a stream with a pending change.

This touches lib/zlib.js and src/node_zlib.cc like #67603; I'm happy to rebase on top of it or the other way around, whichever lands first.

AI-assisted work. All changes reviewed by a human.

Apply `params()` changes as an ordered operation before the next queued
write starts, so `deflateParams()` can no longer run on the threadpool
concurrently with `deflate()` on the same stream, and make the native
`params()` binding throw while a write is in progress. Skip the change if
the stream was destroyed or errored in the meantime. Add regression tests.

Assisted-By: OpenAI GPT-5.6 Sol <openai/gpt-5.6-sol>
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
@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 19, 2026
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.72%. Comparing base (d9e18d5) to head (8583d02).
⚠️ Report is 32 commits behind head on main.

Files with missing lines Patch % Lines
lib/zlib.js 83.87% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67609      +/-   ##
==========================================
- Coverage   90.72%   90.72%   -0.01%     
==========================================
  Files         801      801              
  Lines      280809   280823      +14     
  Branches    54212    54216       +4     
==========================================
- Hits       254776   254765      -11     
- Misses      16209    16217       +8     
- Partials     9824     9841      +17     
Files with missing lines Coverage Δ
src/node_zlib.cc 80.48% <100.00%> (+0.05%) ⬆️
lib/zlib.js 98.14% <83.87%> (-0.28%) ⬇️

... and 22 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants