Skip to content

Chore(remote-test-client): Generalize the timeout to all connections - #164262

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
PaulDance:test-client-connect-timeout
Nov 1, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
PaulDance:test-client-connect-timeout

Conversation

@PaulDance

Copy link
Copy Markdown
Contributor

If a busy CI network or a Quirky EMUlator is used, then the OS default connection timeout may not be enough in order to successfully reach the remote device in time, leading to flaky test failures. As a first attempt to address the slight problem, this therefore proposes to extend the already-existing timeout configuration to the remaining performed connections. This way, all connections are effectively configured by the tool's dedicated environment variable or its default. In practice, it seems to have successfully fixed the issues we had.

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 13, 2026
@PaulDance
PaulDance marked this pull request as ready for review October 13, 2026 15:23
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 13, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 13, 2026
@rustbot

rustbot commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Fallback group: @Mark-Simulacrum, @jieyouxu
  • @Mark-Simulacrum, @jieyouxu expanded to Mark-Simulacrum, jieyouxu
  • Random selection from Mark-Simulacrum, jieyouxu

@PaulDance
PaulDance force-pushed the test-client-connect-timeout branch from 26b3032 to 8414f16 Compare October 15, 2026 13:24
@rustbot

This comment has been minimized.

let start = Instant::now();

// `TcpStream::connect_timeout` may fail earlier than the specified timeout,
// especially under Linux, so loop to extend it to the overall timeout.

@Mark-Simulacrum Mark-Simulacrum Oct 25, 2026 •

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.

Can you say more about this?

It seems like at least one of the cases we're extending is the ConnectionRefused -- presumably that is expected and should happen on ~every platform if we get a RST back from the remote end faster than the timeout?

I think framing that as a "bug" (or at least that's how I read this comment) isn't right; it's just that connect_timeout is timing out a lack of result from the remote end, while what we want here is to retry until the connect succeeds?

View changes since the review

@PaulDance PaulDance Oct 26, 2026 •

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.

Yes, sorry for the lack of clarity, I rushed this specific part a bit.

For context, we compile and run nightly tests for the x86 and x86_64 Win7 targets in CI under Linux using this remote testing framework with VMs running on a KubeVirt cluster that ends up using QEMU. In doing so, we have recently been observing some weird timeouts when the client attempts to connect to the remote testing server. When this happens, the SSH server installed on the VMs can be connected to just fine, suggesting the networking actually works, so we're suspecting that QEMU is just being buggy here.

My first iteration of the current PR was to use a single call to TcpStream::connect_timeout and that seemed to have fixed the issue in practice for about a week. However, some more failures happened later on, and in the CI logs I could see that the interval between the failing test's start and its failure on kind: TimedOut was between one and two minutes while the set timeout was ten minutes. That felt very surprising, hence my phrasing of the concerned comment.

Looking at the function's implementation details (disclaimer: with Claude Code; not used to generate any code afterwards, though), it seemed that it could reach a timeout sooner than the requested timeout due to Linux-specific kernel configuration effectively capping TCP timeouts, even though it also loops with time measurements. The short term fix and second iteration was therefore to add yet another time-measured loop around the function to ensure the requested timeout is fully used, and that seems to work in practice for now, at least for our use case.

I updated the comment to clarify that a bit by mentioning connection refusals specifically. I can expand on it further if you want.


A simple reproducer of the issue is the following:

let start = Instant::now();
dbg!(TcpStream::connect_timeout(
    &"192.168.10.1:8080".parse().unwrap(),
    Duration::from_mins(10),
));
dbg!(start.elapsed());

On my Linux machine and my home network where 192.168.10.1 is its router that definitely does not listen on 8080, the following is displayed (omitting some line and code info from dbg!):

[..] .. = Err(
    Os {
        code: 110,
        kind: TimedOut,
        message: "Connection timed out",
    },
)
[..] start.elapsed() = 135.195878081s

It shows that the effective timeout is a bit more than two minutes while the requested one is ten, i.e. considerably higher. This seems at the very least surprising, if not a bug, considering it is not particularly documented. I didn't open a dedicated issue right away because it looked like it could have been intentional, but I can definitely open one if you don't know of any good explanation or justification for this right away.

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.

I think we should at least document the behavior, so let's cut an issue. I suspect what you're seeing is that the destination is not sending back RSTs, and we're hitting a different timeout unrelated to the 10 minutes you pass in? But needs some investigation (packet capture) and it makes sense to me to decide whether to update documentation, cite some reference, or perhaps adjust the implementation to loop more aggressively (i.e., refuse to return an error until 10 minutes have elapsed).

For the purposes of remote-test-client I'm OK retrying connect() on TimedOut or ConnectionRefused, so this seems fine.

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.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 25, 2026
@rustbot

rustbot commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

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

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 25, 2026
If a busy CI network or a Quirky EMUlator is used, then the OS default
connection timeout may not be enough in order to successfully reach the
remote device in time, leading to flaky test failures. As a first
attempt to address the slight problem, this therefore proposes to extend
the already-existing timeout configuration to the remaining performed
connections. This way, all connections are effectively configured by the
tool's dedicated environment variable or its default. In practice, it
seems to have successfully fixed the issues we had.

Signed-off-by: Paul Mabileau <[email protected]>
@PaulDance
PaulDance force-pushed the test-client-connect-timeout branch from 8414f16 to ef1bc9d Compare October 26, 2026 13:24
@rustbot

rustbot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@PaulDance

Copy link
Copy Markdown
Contributor Author

@rustbot ready

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

@Mark-Simulacrum Mark-Simulacrum 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.

@rust-bors

rust-bors Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ef1bc9d has been approved by Mark-Simulacrum

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-review Status: Awaiting review from the assignee but also interested parties. labels Nov 1, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 1, 2026
…out, r=Mark-Simulacrum

Chore(remote-test-client): Generalize the timeout to all connections

If a busy CI network or a Quirky EMUlator is used, then the OS default connection timeout may not be enough in order to successfully reach the remote device in time, leading to flaky test failures. As a first attempt to address the slight problem, this therefore proposes to extend the already-existing timeout configuration to the remaining performed connections. This way, all connections are effectively configured by the tool's dedicated environment variable or its default. In practice, it seems to have successfully fixed the issues we had.
rust-bors Bot pushed a commit that referenced this pull request Nov 1, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #163757 (lib: specialize vec extend_with)
 - #164262 (Chore(remote-test-client): Generalize the timeout to all connections)
 - #165245 (std_detect(linux): Use static CStr over allocating for terminator)
 - #164359 (Refactor box downcasting methods)
 - #165086 (Improve mem::take wording)
 - #165088 ([small] Tweak suggestions in struct literal resolve errors)
 - #165276 (Fix FCW issue template labels)
@rust-bors
rust-bors Bot merged commit 46835f4 into rust-lang:main Nov 1, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Nov 1, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 1, 2026
Rollup merge of #164262 - PaulDance:test-client-connect-timeout, r=Mark-Simulacrum

Chore(remote-test-client): Generalize the timeout to all connections

If a busy CI network or a Quirky EMUlator is used, then the OS default connection timeout may not be enough in order to successfully reach the remote device in time, leading to flaky test failures. As a first attempt to address the slight problem, this therefore proposes to extend the already-existing timeout configuration to the remaining performed connections. This way, all connections are effectively configured by the tool's dedicated environment variable or its default. In practice, it seems to have successfully fixed the issues we had.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants