-
Notifications
You must be signed in to change notification settings - Fork 724
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
bindings: fix handling of s2n_shutdown errors #4358
Conversation
b8cca66
to
7670de4
Compare
// write the close_notify message that the server needs. | ||
// Because time is mocked for testing, this does not actually take 10 minutes. | ||
// TODO: replace this with a half-close once the bindings support half-close. | ||
_ = time::timeout(time::Duration::from_secs(600), client.shutdown()).await; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily in this PR, but I think we should add this as a suggestion in our documentation.
Note that shutdown().await will wait for peer acknowledgement for an unbounded amount of time. Resource sensitive consumers should consider calling shutdown with an explicit timeout added
Or something like that.
573519f
to
0a0107a
Compare
// poll methods shouldn't be called again after returning Ready, but | ||
// nothing actually prevents it so poll_shutdown should handle it. | ||
// s2n_shutdown can be polled indefinitely after succeeding, but not after failing. | ||
// s2n_tls::error::Error isn't cloneable, so we can't just return the same error | ||
// if poll_shutdown is called again. Instead, save a different error. | ||
let next_error = Error::application("Shutdown called again after error".into()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems reasonable!
Description of changes:
I think I found a bug in shutdown. If s2n_shutdown fails, we never close the underlying stream. I fixed it and added new tests for the interaction between s2n_shutdown failures and underlying stream failures.
I also refactored the blinding / shutdown logic. Previously, blinding and shutdown errors were all tangled up; polling blinding could actually return a previous shutdown error and we stored shutdown errors by calling set_blinding_timer. It made the flow of shutdown very hard to follow. Blinding and shutdown errors are unrelated and can/should be handled by completely separate logic and state.
Testing:
New tests of s2n_shutdown errors in shutdown, particularly the interaction with tcp shutdown.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.