Repository navigation
zlib: prevent concurrent parameter changes - #67609
ShogunPanda wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #67609 +/- ##
==========================================
- Coverage 90.72% 90.59% -0.14%
==========================================
Files 801 802 +1
Lines 280809 287062 +6253
Branches 54212 55437 +1225
==========================================
+ Hits 254776 260057 +5281
- Misses 16209 17100 +891
- Partials 9824 9905 +81
🚀 New features to boost your workflow:
|
8583d02 to
9d2f344
Compare
There was a problem hiding this comment.
the usage of bind() I think it's still a bit faster due to the non-allocation of closure.
There was a problem hiding this comment.
Done. I restored the top-level paramsAfterFlushCallback() helper and _transform() now passes paramsAfterFlushCallback.bind(this, level, strategy, cb) to processChunk(), so there is no per-call closure anymore.
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>
9d2f344 to
58cbb83
Compare
|
I also added tests for the paths Codecov reported as uncovered: destroying the stream while the flush carrying a parameter change is still running on the threadpool (the change is not applied to the closed handle), and requesting values that are already applied or already queued (no extra write is queued and the callback is still called asynchronously). |
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, sodeflateParams()anddeflate()could run concurrently on the samez_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, likereset()already does. A change that is still pending when the stream is destroyed or errors is not applied. Consecutiveparams()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.jsandsrc/node_zlib.cclike #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.