Fix crash in HTTPResumableUploadChannel when parent channel is closed#304
Merged
Lukasa merged 4 commits intoapple:mainfrom Jan 28, 2026
Merged
Fix crash in HTTPResumableUploadChannel when parent channel is closed#304Lukasa merged 4 commits intoapple:mainfrom
Lukasa merged 4 commits intoapple:mainfrom
Conversation
guoye-zhang
approved these changes
Jan 23, 2026
8e1bc44 to
37254a6
Compare
Contributor
Author
|
This is the test reproducing the issue in CI: Now I'll push the fix commit. |
eabb04f to
f72b45b
Compare
Contributor
Author
|
OK, the test is now passing. This PR is just blocked on us getting a new NIO release with the testing support we need. |
FranzBusch
pushed a commit
to FranzBusch/swift-nio
that referenced
this pull request
Jan 27, 2026
…tion` if channel is closed (apple#3495) ### Motivation: Channels based on `BaseSocketChannel` throw in both `getOption` and `setOption` if the channel has been closed, since the `setsockopt` will fail. However, the current behavior of `EmbeddedChannel` is options remain writable and readable on closed channels. There are situations where we'd like to be able to model the runtime behaviour of the real channel in tests, e.g. to test this fix: apple/swift-nio-extras#304. ### Modifications: - Add API to enable throwing in `EmbeddedChannel.getOption` and `.setOption` if channel is closed. - Add a test for this new behavior. ### Result: - New API to enable throwing in `EmbeddedChannel.getOption` and `.setOption` if channel is closed. - No observable change for existing users of `EmbeddedChannel`.
270cd3f to
6711683
Compare
Contributor
Author
|
OK, now that we have a NIO release with the EmbeddedChannel support for the test, I've updated the NIO dependency and this PR is ready to review. |
gjcairo
approved these changes
Jan 28, 2026
Lukasa
approved these changes
Jan 28, 2026
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.
Motivation:
Servers using
HTTPResumableUploadHandlercan currently crash during channel creation if the parent channel is closed.During channel creation, the handler will inherit the
autoReadoption from the parent channel:The force-unwrap of
syncOptionsis justified because this handler can only be used with channels that support sync options, but the force-try can trigger a crash with supported channels when the connection is interrupted.NIO's
BaseSocketChannelwill throw an error if the channel is closed, and this presents a race window and we've observed crashes with the following output:Modifications:
Replace the force-try with
try?to prevent the crash. Given it looks like the only reason this would throw is if the connection is closed, the channel is not long for this world, and so the default value used is moot. However, I've defaulted this tofalseas it's the most conservative option.I also wrote a test that uses new
EmbeddedChannelAPI that was added to support this fix. The PR has been structured to add the test first, showing it failing, and then add the fix commit, which then shows the test passing.Result:
The server will no longer crash when parent channels close during upload operations.