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
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