Repository navigation
Chore(remote-test-client): Generalize the timeout to all connections - #164262
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
26b3032 to
8414f16
Compare
This comment has been minimized.
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Reminder, once the PR becomes ready for a review, use |
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]>
8414f16 to
ef1bc9d
Compare
|
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. |
|
@rustbot ready |
…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.
…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)
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.
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.