Document transient connection errors from TcpListener::accept#158074
Conversation
`accept` can return an error that belongs to a single incoming connection, not to the listener itself, for example a connection aborted by the peer before it could be accepted. The listener stays usable in that case, so code serving a long-lived listener usually wants to log the error and keep accepting connections rather than treat it as fatal. This was previously undocumented. - Add an `# Errors` section to `accept` that describes this behavior without listing specific error codes. - Note that `Interrupted` errors are retried internally on Unix. - Point `incoming` and `into_incoming` at `accept` for the same details.
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @Darksonn (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
| /// # Errors | ||
| /// | ||
| /// Some errors returned by this function relate to a single incoming | ||
| /// connection that failed before it could be accepted, such as one aborted | ||
| /// by the peer ([`ConnectionAborted`]). Such an error does not indicate a | ||
| /// problem with the listener itself, which remains usable. Code serving a | ||
| /// long-lived listener will usually want to log the error and continue | ||
| /// accepting connections rather than treat it as fatal. Which errors can | ||
| /// occur this way is platform-specific. | ||
| /// | ||
| /// On Unix, [`Interrupted`] errors are retried internally rather than being | ||
| /// returned. |
There was a problem hiding this comment.
If we're going to start documenting the set of errors, then we should probably also mention that it can fail with an error if the FD limit has been reached, in which case the call can be retried once other fds have been closed (often done via a timeout).
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
|
May also be worth mentioning ENOMEM if an allocation failed while trying to accept it. |
| /// - An error from reaching the per-process or system-wide open file | ||
| /// descriptor limit. The call can be retried once other file descriptors | ||
| /// have been closed, typically after a short delay. |
There was a problem hiding this comment.
Which error kind is used for this?
There was a problem hiding this comment.
It's Uncategorized. EMFILE/ENFILE aren't mapped in decode_error_kind, so they're only distinguishable via raw_os_error(), which is what std itself does:
rust/library/std/src/sys/process/unix/unix.rs
Lines 513 to 517 in 693b3e4
With no matchable kind, I went with prose here.
|
Added the On scope: I kept this as a non-exhaustive list ("include, but are not limited |
|
Keeping it non-exhasutive is good. |
|
Looks good, thanks. @bors r+ rollup |
…rrors, r=Darksonn Document transient connection errors from TcpListener::accept `TcpListener::accept` can return an error that belongs to a single incoming connection, not to the listener, for example a connection aborted by the peer before it could be accepted (`ConnectionAborted`). The listener stays usable, so a server looping over connections usually wants to log the error and keep accepting rather than treat it as fatal. This was not documented, and the `incoming` example treated every error as a failed connection. This implements the libs-team decision in rust-lang#142557: document these transient errors instead of changing `accept` to retry them, since retrying would hide errors that some callers want to observe. Changes: - Add an `# Errors` section to `accept` describing this behavior, without listing specific error codes since some may be more permanent than others. - Note that `Interrupted` errors are retried internally on Unix. - Add the same pointer to `incoming` and `into_incoming`, which are `accept` in a loop. Addresses rust-lang#142557. r? rust-lang/libs
…rrors, r=Darksonn Document transient connection errors from TcpListener::accept `TcpListener::accept` can return an error that belongs to a single incoming connection, not to the listener, for example a connection aborted by the peer before it could be accepted (`ConnectionAborted`). The listener stays usable, so a server looping over connections usually wants to log the error and keep accepting rather than treat it as fatal. This was not documented, and the `incoming` example treated every error as a failed connection. This implements the libs-team decision in rust-lang#142557: document these transient errors instead of changing `accept` to retry them, since retrying would hide errors that some callers want to observe. Changes: - Add an `# Errors` section to `accept` describing this behavior, without listing specific error codes since some may be more permanent than others. - Note that `Interrupted` errors are retried internally on Unix. - Add the same pointer to `incoming` and `into_incoming`, which are `accept` in a loop. Addresses rust-lang#142557. r? rust-lang/libs
…uwer Rollup of 6 pull requests Successful merges: - #158026 (`RegionValues`: disable unnecessary range check) - #156795 (Handle generic reborrow in expression-use adjustment walking) - #157694 (Enhance documentation on wake call memory ordering) - #158034 (Fix reborrow source expression visits) - #158074 (Document transient connection errors from TcpListener::accept) - #158086 (renovate: Loosen dashboard approval and adopt recommended config)
…rrors, r=Darksonn Document transient connection errors from TcpListener::accept `TcpListener::accept` can return an error that belongs to a single incoming connection, not to the listener, for example a connection aborted by the peer before it could be accepted (`ConnectionAborted`). The listener stays usable, so a server looping over connections usually wants to log the error and keep accepting rather than treat it as fatal. This was not documented, and the `incoming` example treated every error as a failed connection. This implements the libs-team decision in rust-lang#142557: document these transient errors instead of changing `accept` to retry them, since retrying would hide errors that some callers want to observe. Changes: - Add an `# Errors` section to `accept` describing this behavior, without listing specific error codes since some may be more permanent than others. - Note that `Interrupted` errors are retried internally on Unix. - Add the same pointer to `incoming` and `into_incoming`, which are `accept` in a loop. Addresses rust-lang#142557. r? rust-lang/libs
…uwer Rollup of 10 pull requests Successful merges: - #158026 (`RegionValues`: disable unnecessary range check) - #156795 (Handle generic reborrow in expression-use adjustment walking) - #157694 (Enhance documentation on wake call memory ordering) - #157935 (Make `proc_macro::ConversionErrorKind` non exhaustive) - #158002 (Replace `unwrap` with `expect` in `get_module_children`) - #158034 (Fix reborrow source expression visits) - #158072 (Bump thin-vec to 0.2.18 to address RUSTSEC-2026-0103) - #158074 (Document transient connection errors from TcpListener::accept) - #158077 (rustdoc-json-types: Replace bincode dev-dependency with postcard) - #158086 (renovate: Loosen dashboard approval and adopt recommended config)
…uwer Rollup of 10 pull requests Successful merges: - #158026 (`RegionValues`: disable unnecessary range check) - #156795 (Handle generic reborrow in expression-use adjustment walking) - #157694 (Enhance documentation on wake call memory ordering) - #157935 (Make `proc_macro::ConversionErrorKind` non exhaustive) - #158002 (Replace `unwrap` with `expect` in `get_module_children`) - #158034 (Fix reborrow source expression visits) - #158072 (Bump thin-vec to 0.2.18 to address RUSTSEC-2026-0103) - #158074 (Document transient connection errors from TcpListener::accept) - #158077 (rustdoc-json-types: Replace bincode dev-dependency with postcard) - #158086 (renovate: Loosen dashboard approval and adopt recommended config)
Rollup of 12 pull requests Successful merges: - #156795 (Handle generic reborrow in expression-use adjustment walking) - #157694 (Enhance documentation on wake call memory ordering) - #157935 (Make `proc_macro::ConversionErrorKind` non exhaustive) - #158002 (Replace `unwrap` with `expect` in `get_module_children`) - #158009 (Reject `impl const Trait` since the right syntax is `const impl Trait` now) - #158034 (Fix reborrow source expression visits) - #158072 (Bump thin-vec to 0.2.18 to address RUSTSEC-2026-0103) - #158074 (Document transient connection errors from TcpListener::accept) - #158077 (rustdoc-json-types: Replace bincode dev-dependency with postcard) - #158086 (renovate: Loosen dashboard approval and adopt recommended config) - #158088 (codegen_ssa: no dbginfo for scalable vec local w/ `-O0`) - #158089 (Fix invalid "jump-to-def" doc link generation when an item has a `derive` proc-macro)
Rollup merge of #158074 - valentynkt:docs/accept-transient-errors, r=Darksonn Document transient connection errors from TcpListener::accept `TcpListener::accept` can return an error that belongs to a single incoming connection, not to the listener, for example a connection aborted by the peer before it could be accepted (`ConnectionAborted`). The listener stays usable, so a server looping over connections usually wants to log the error and keep accepting rather than treat it as fatal. This was not documented, and the `incoming` example treated every error as a failed connection. This implements the libs-team decision in #142557: document these transient errors instead of changing `accept` to retry them, since retrying would hide errors that some callers want to observe. Changes: - Add an `# Errors` section to `accept` describing this behavior, without listing specific error codes since some may be more permanent than others. - Note that `Interrupted` errors are retried internally on Unix. - Add the same pointer to `incoming` and `into_incoming`, which are `accept` in a loop. Addresses #142557. r? rust-lang/libs
Rollup of 12 pull requests Successful merges: - rust-lang/rust#156795 (Handle generic reborrow in expression-use adjustment walking) - rust-lang/rust#157694 (Enhance documentation on wake call memory ordering) - rust-lang/rust#157935 (Make `proc_macro::ConversionErrorKind` non exhaustive) - rust-lang/rust#158002 (Replace `unwrap` with `expect` in `get_module_children`) - rust-lang/rust#158009 (Reject `impl const Trait` since the right syntax is `const impl Trait` now) - rust-lang/rust#158034 (Fix reborrow source expression visits) - rust-lang/rust#158072 (Bump thin-vec to 0.2.18 to address RUSTSEC-2026-0103) - rust-lang/rust#158074 (Document transient connection errors from TcpListener::accept) - rust-lang/rust#158077 (rustdoc-json-types: Replace bincode dev-dependency with postcard) - rust-lang/rust#158086 (renovate: Loosen dashboard approval and adopt recommended config) - rust-lang/rust#158088 (codegen_ssa: no dbginfo for scalable vec local w/ `-O0`) - rust-lang/rust#158089 (Fix invalid "jump-to-def" doc link generation when an item has a `derive` proc-macro)
TcpListener::acceptcan return an error that belongs to a single incomingconnection, not to the listener, for example a connection aborted by the peer
before it could be accepted (
ConnectionAborted). The listener stays usable, soa server looping over connections usually wants to log the error and keep
accepting rather than treat it as fatal. This was not documented, and the
incomingexample treated every error as a failed connection.This implements the libs-team decision in #142557: document these transient
errors instead of changing
acceptto retry them, since retrying would hideerrors that some callers want to observe.
Changes:
# Errorssection toacceptdescribing this behavior, withoutlisting specific error codes since some may be more permanent than others.
Interruptederrors are retried internally on Unix.incomingandinto_incoming, which areacceptin a loop.
Addresses #142557.
r? rust-lang/libs