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

bindings: fix handling of s2n_shutdown errors #4358

Merged
merged 4 commits into from
Jan 19, 2024

Conversation

lrstewart
Copy link
Contributor

@lrstewart lrstewart commented Jan 11, 2024

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.

@github-actions github-actions bot added the s2n-core team label Jan 11, 2024
@lrstewart lrstewart force-pushed the blinding_tokio branch 2 times, most recently from b8cca66 to 7670de4 Compare January 11, 2024 08:09
@lrstewart lrstewart marked this pull request as ready for review January 12, 2024 05:33
// 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;
Copy link
Contributor

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.

Comment on lines +381 to +386
// 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());
Copy link
Contributor

Choose a reason for hiding this comment

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

seems reasonable!

@lrstewart lrstewart requested a review from jmayclin January 18, 2024 23:08
@lrstewart lrstewart enabled auto-merge (squash) January 19, 2024 01:00
@lrstewart lrstewart merged commit 5744711 into aws:main Jan 19, 2024
25 checks passed
jmayclin pushed a commit to jmayclin/s2n-tls that referenced this pull request Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants