Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash if connection is closed very early #671

Merged
merged 3 commits into from
Mar 14, 2023

Conversation

dnadoba
Copy link
Collaborator

@dnadoba dnadoba commented Mar 13, 2023

If the channel is closed before flatMap is executed, all ChannelHandler are removed and TLSEventsHandler is therefore not present either. We need to tolerate this even though it is very rare.

Testing ideas welcome.

Fixes #670

If the channel is closed before flatMap is executed, all ChannelHandler are removed and `TLSEventsHandler` is therefore not present either. We need to tolerate this even though it is very rare.

Testing ideas welcome.

Fixes swift-server#670
@dnadoba dnadoba added the semver/minor For PRs that when merged cause a bump of the minor version, ie. 1.x.0 -> 1.(x+1).0 label Mar 13, 2023
channel.pipeline.removeHandler(tlsEventHandler).map { (channel, negotiated) }
}
} catch {
precondition(channel.isActive == false, "if the channel is still active then TLSEventsHandler must be present but got error \(error)")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this precondition is particularly wise: the connection pool will appropriately handle this. Let's drop it to assert instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d0d1cee

@Lukasa
Copy link
Collaborator

Lukasa commented Mar 14, 2023

Can you clean up soundness?

@dnadoba dnadoba enabled auto-merge (squash) March 14, 2023 10:31
@dnadoba dnadoba merged commit 423fd0b into swift-server:main Mar 14, 2023
@dnadoba dnadoba deleted the dn-fix-early-close-crash branch March 14, 2023 11:05
@dnadoba dnadoba added semver/patch For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) and removed semver/minor For PRs that when merged cause a bump of the minor version, ie. 1.x.0 -> 1.(x+1).0 labels Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fatal error: 'try!' expression unexpectedly raised an error: NIOCore.ChannelPipelineError.notFound
2 participants