Fix polling (neon) driver reentrancy panic on in-read filter writes#906
Open
Meemaw wants to merge 1 commit into
Open
Fix polling (neon) driver reentrancy panic on in-read filter writes#906Meemaw wants to merge 1 commit into
Meemaw wants to merge 1 commit into
Conversation
The polling driver's `StreamOpsInner::with` is `Cell::take().unwrap()` with no reentrancy guard. The driver calls `StreamItem::read` (-> filter read processing -> `update_read_status`) *inside* a `with` scope. If a filter produces >= `write_buf_threshold` (8192) bytes of write data during read processing while writes are paused, the io stream initiates a direct write (`Handle::write` -> `WeakStreamCtl::with`), which re-enters `with` on the same already-taken cell -> `None.unwrap()` panic, killing the arbiter thread and the connection. This is the exact failure mode of a TLS-style filter that emits a large handshake/control burst in response to incoming records. Fix: route direct writes through a new `write_stream` that, when the streams slab is already borrowed (we are inside event handling), defers the write to `check_delayed_writes`, draining it once the slab is released - mirroring the existing `delayed_drop` mechanism. No more reentrant take. Regression test `test_filter_large_write_during_read_processing` exercises the polling backend (the default driver on non-Linux hosts): it panics with "called `Option::unwrap()` on a `None` value" at polling/stream.rs without this fix and passes with it.
2d7da74 to
55afd4a
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #906 +/- ##
==========================================
+ Coverage 90.25% 90.27% +0.01%
==========================================
Files 240 240
Lines 34992 35024 +32
==========================================
+ Hits 31582 31617 +35
+ Misses 3410 3407 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The polling driver's
StreamOpsInner::withisCell::take().unwrap()with no reentrancy guard. The driver callsStreamItem::read(-> filter read processing ->update_read_status) inside awithscope. If a filter produces >=write_buf_threshold(8192) bytes of write data during read processing while writes are paused, the io stream initiates a direct write (Handle::write->WeakStreamCtl::with), which re-enterswithon the same already-taken cell ->None.unwrap()panic, killing the arbiter thread and the connection.This is the exact failure mode of a TLS-style filter that emits a large handshake/control burst in response to incoming records.
Fix: route direct writes through a new
write_streamthat, when the streams slab is already borrowed (we are inside event handling), defers the write tocheck_delayed_writes, draining it once the slab is releaseddelayed_dropmechanism. No more reentrant take.Regression test
test_filter_large_write_during_read_processingexercises the polling backend (the default driver on non-Linux hosts): it panics with "calledOption::unwrap()on aNonevalue" at polling/stream.rs without this fix and passes with it.