mirror of
https://github.com/apple/swift-nio-extras
synced 2026-11-24 04:37:58 +00:00
### Motivation: `NIOHTTPRequestDecompressor` / `NIOHTTPResponseDecompressor` keep their state in a stored `var decompressor` (a `struct`) and forwarded downstream (`fireChannelRead` / `fireErrorCaught`) from inside that struct's `mutating` `channelRead`, i.e. while an exclusive (modify) access to the stored property was still open. If firing downstream synchronously re-enters the handler's `channelRead`, a second exclusive access is opened and the program traps with `Fatal access conflict detected` (SIGABRT). This reproduces in production with AsyncHTTPClient over HTTP/2 and `decompression = .enabled`: a compressed response is mid-decompress when a decompression error closes the stream, and the buffered read re-delivered on the stream-close path re-enters `channelRead` on the same decompressor. ### Modifications: - The body decompression is now expressed as a `NIOSingleStepByteToMessageDecoder`, driven by a `NIOSingleStepByteToMessageProcessor`. The handler pulls one decompressed buffer at a time and forwards it only after `decode` has returned, so the decoder relinquishes its exclusive access before anything is fired downstream. - The shared driver is now a `class`, so the head/end forwarding paths are re-entrancy safe for the same reason. - The zlib stream is torn down in the decoder's `deinit`, which additionally fixes a leak when a message ends without a final `.end`. - No public API changes. ### Result: Synchronous re-entry of `channelRead` no longer traps. Adds regression tests covering the forward and error re-entry paths on both decompressors; all existing decompression tests (limits, trailing data, truncation, multi-message reuse) continue to pass. Fixes #314 --------- Co-authored-by: George Barnett <gbarnett@apple.com>