mirror of
https://github.com/apple/swift-nio-extras
synced 2026-11-22 04:30:42 +00:00
Fix `HTTPResumableUploadHandler` silently dropping all responses after the first request on a connection. ### Motivation: `HTTPResumableUploadHandler` forwards all outbound operations through its stored `ChannelHandlerContext`, which is set only in `handlerAdded` and cleared by `detach()` whenever an upload releases the handler. When a second request arrives on the same channel — the normal case for HTTP/1.1 with keep-alive — `channelRead` calls `resetUpload`, which ends the previous upload. That synchronously detaches the handler and clears its context, and nothing restores it before the new upload is attached. Every response write for the second and subsequent requests then hits `self.context?.write(...)` as a no-op: the response is silently dropped, write promises never complete, and `read()` forwarding to the parent channel stops, so the client hangs until it times out. The existing tests never caught this because each test sends one request per `EmbeddedChannel`; resumption is only exercised across separate channels, and per-stream channels (HTTP/2) recreate the handler per request, which also masks the bug. ### Modifications: - Restore `self.context` in `resetUpload(context:)` after ending the previous upload. - Add `testNonUploadKeepAlive` and `testResumableUploadKeepAlive`, which send a second request on the same `EmbeddedChannel` for pass-through traffic and after a completed upload creation respectively. Both fail without the fix. ### Result: Connections handled by `HTTPResumableUploadHandler` can serve more than one request: responses to the second and subsequent requests on a keep-alive connection are delivered instead of being silently dropped. Fixes #318 Co-authored-by: Cory Benfield <lukasa@apple.com>