-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Prevent server from exiting on ECONNABORTED #1874
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6c399ca
Prevent server from exiting on ECONNABORTED
grembo dd4ce1b
Handle ECONNABORTED without breaking APIs
grembo 355b8b4
Next iteration based on feedback
grembo bc7196d
More review feedback
grembo 25b3b7a
Only use std::io if needed
grembo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,19 @@ where | |
let mut incoming = pin!(incoming); | ||
|
||
while let Some(item) = incoming.next().await { | ||
yield item.map(ServerIo::new_io)? | ||
if let Err(e) = item { | ||
if let Some(e) = Into::<crate::Error>::into(e).downcast_ref::<std::io::Error>() { | ||
tracing::debug!(message = "Accept loop error.", error = %e); | ||
if e.kind() == std::io::ErrorKind::ConnectionAborted { | ||
continue; | ||
} | ||
} else { | ||
tracing::debug!(message = "Accept loop error (unknown error)."); | ||
} | ||
break; | ||
} else { | ||
yield item.map(ServerIo::new_io)? | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
could also be written as
but in terms of readability and diff, I opted for the former (any better ideas?). |
||
} | ||
|
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.
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.
I think this is broadly acceptable but I have bunch of stylistic suggestions.
First, use a match for the top-level error extraction:
This reduces rightward drift.
Second, I would expect we can just call
err.into()
and don't need the wholeInto::<crate::Error>::into(e)
dance?Third, for the debug messages, I think we should not use an explicit
message =
name but use the general form which is having the message after the "structured" argument (sotracing::debug!(error = %e, "accept loop error");
). Note that error messages should be all-lowercase and not have any.
at the end.Fourth, please import
io
at the top of the file so we can drop thestd::
prefixes here.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.
Personally I don't have much of an opinion on these style issues, so I just changed things as requested.
There is one thing I really didn't like though, which was error extraction, which would have looked like this:
So instead, I went with clearly defined Ok and Err branches (horizontal drift is IMHO acceptable). I'm quite happy with the readability of the outcome (especially having only one continue statement, pointing out the exception, and no break statements). This should also be relatively easy to parse to people who are not familiar with all language features + the diff to the master branch is very easy to understand.