Skip to content

fix: don't break out of run_connection_attempts with futures left to try - #8458

Closed
link2xt wants to merge 1 commit into
mainfrom
link2xt/fix-run_connection_attempts
Closed

fix: don't break out of run_connection_attempts with futures left to try#8458
link2xt wants to merge 1 commit into
mainfrom
link2xt/fix-run_connection_attempts

Conversation

@link2xt

@link2xt link2xt commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

If we ran out of running connection attempts,
but there are still futures not added to the connection attempt set, we should not break out with the list of errors yet, but move another future into the attempt set
even if the delay has not expired yet.

Otherwise it is possible to resolve the hostname into two IPs, try one that fails immediately,
then break out of the loop without trying the second one and only report the error for the first one.

It is still not nice that we may start another connection attempt right before the next delay expires, so we may start two connections attempts almost simultaneously, but it is not critical.

…o try

If we ran out of running connection attempts,
but there are still futures not added to the connection attempt set,
we should not break out with the list of errors yet,
but move another future into the attempt set
even if the delay has not expired yet.

Otherwise it is possible to resolve the hostname into two IPs,
try one that fails immediately,
then break out of the loop without trying the second one
and only report the error for the first one.

It is still not nice that we may start another connection attempt
right before the next delay expires, so we may start two connections attempts
almost simultaneously, but it is not critical.
@link2xt link2xt added the bug Something is not working label Jul 24, 2026
Comment thread src/net.rs
}
}
None => {
// Out of connection attempts.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This comment here was wrong, it was possible that we have empty connection_attempt_set, but non-empty futures.

@link2xt

link2xt commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

I have not seen any logs that look like having this problem.

I was looking at the log line DeltaChat: [accId=1] src/imap.rs:368: IMAP failed to connect to chtml.ca:443:tls: All connection attempts failed: Connection to [2607:5300:205:200::21eb]:443 failed: Network is unreachable (os error 101); timed out.. This log line is actually not wrong, it says that IPv6 failed as unreachable, but "timed out" is for the IPv4 candidate and i overlooked it because the error does not include the IPv4 address.

So i have looked at the code for no good reason, but the code does not look correct.

Comment thread src/net.rs
/// and runs them until one of them succeeds
/// or all of them fail.
///
/// If all connection attempts fail, returns the first error.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The comment is outdated, need to update as we return all errors.

@link2xt

link2xt commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

The function should be unit-tested with some futures that sleep and return success/errors.

@link2xt link2xt removed the bug Something is not working label Jul 24, 2026
@link2xt link2xt closed this Jul 24, 2026
@link2xt
link2xt deleted the link2xt/fix-run_connection_attempts branch July 24, 2026 19:53
@link2xt

link2xt commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

Replaced with #8459

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant