Skip to content

Document transient connection errors from TcpListener::accept#158074

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
valentynkit:docs/accept-transient-errors
Jun 18, 2026
Merged

Document transient connection errors from TcpListener::accept#158074
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
valentynkit:docs/accept-transient-errors

Conversation

@valentynkit

@valentynkit valentynkit commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

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

`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.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 18, 2026
@rustbot

rustbot commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • rust-lang/libs expanded to 11 candidates
  • Random selection from Darksonn, Mark-Simulacrum, clarfonthey, jhpratt

@Darksonn Darksonn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm. There are a lot of different errors it can return. This only documents one case.

View changes since this review

Comment thread library/std/src/net/tcp.rs Outdated
Comment on lines +879 to +890
/// # 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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).

@Darksonn Darksonn added A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` labels Jun 18, 2026
@Darksonn

Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 18, 2026
@rustbot

rustbot commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Darksonn

Copy link
Copy Markdown
Member

May also be worth mentioning ENOMEM if an allocation failed while trying to accept it.

@Darksonn Darksonn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall LGTM, just one more thing we could add.

View changes since this review

Comment on lines +889 to +891
/// - 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Which error kind is used for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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:

Err(e) if e.raw_os_error() == Some(libc::EMFILE) => {
// We're temporarily(?) out of file descriptors. In this case pidfd_spawnp would also fail
// Don't update the support flag so we can probe again later.
return Err(e)
}

With no matchable kind, I went with prose here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, that makes sense, thanks.

@valentynkit

Copy link
Copy Markdown
Contributor Author

Added the OutOfMemory case too, thanks!

On scope: I kept this as a non-exhaustive list ("include, but are not limited
to") covering the main retryable cases rather than enumerating everything. Is
that the level you'd prefer, or should I expand it?

@Darksonn

Copy link
Copy Markdown
Member

Keeping it non-exhasutive is good.

@Darksonn

Copy link
Copy Markdown
Member

Looks good, thanks.

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 1447519 has been approved by Darksonn

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 18, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 18, 2026
…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
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 18, 2026
…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
rust-bors Bot pushed a commit that referenced this pull request Jun 18, 2026
…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)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 18, 2026
…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
rust-bors Bot pushed a commit that referenced this pull request Jun 18, 2026
…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)
rust-bors Bot pushed a commit that referenced this pull request Jun 18, 2026
…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)
rust-bors Bot pushed a commit that referenced this pull request Jun 18, 2026
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)
@rust-bors rust-bors Bot merged commit 6433d9b into rust-lang:main Jun 18, 2026
13 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 18, 2026
rust-timer added a commit that referenced this pull request Jun 18, 2026
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
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Jun 19, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants