Skip to content

Fix flakiness in test_tor_connect#4521

Merged
tnull merged 1 commit intolightningdevkit:mainfrom
tankyleo:2026-03-tor-connect-flakiness
Mar 31, 2026
Merged

Fix flakiness in test_tor_connect#4521
tnull merged 1 commit intolightningdevkit:mainfrom
tankyleo:2026-03-tor-connect-flakiness

Conversation

@tankyleo
Copy link
Copy Markdown
Contributor

Fixes #4519

@ldk-reviews-bot
Copy link
Copy Markdown

ldk-reviews-bot commented Mar 30, 2026

👋 Thanks for assigning @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

Comment on lines +1123 to +1127
let mut google_addresses: Vec<_> = "google.com:80".to_socket_addrs().unwrap().collect();
let ipv6_pos = google_addresses.iter().position(|a| a.is_ipv6()).expect("must resolve at least one ipv6 address");
let mut google_ipv6 = google_addresses.remove(ipv6_pos);
let ipv4_pos = google_addresses.iter().position(|a| a.is_ipv4()).expect("must resolve at least one ipv4 address");
let mut google_ipv4 = google_addresses.remove(ipv4_pos);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: to_socket_addrs() performs blocking DNS resolution inside an async fn. For a test this is unlikely to cause issues with the single-threaded #[tokio::test] runtime, but tokio::net::lookup_host("google.com:80") would be the idiomatic async alternative.

More importantly: the two expect calls assume google.com always resolves to both IPv4 and IPv6 addresses. If a CI runner's DNS resolver strips AAAA records (some corporate/restricted environments do this), or if there's a transient DNS hiccup returning only one address family, this introduces a new source of flakiness — which is ironic given the PR's purpose. Consider using find with a fallback/skip instead of expect, e.g.:

let ipv6_pos = match google_addresses.iter().position(|a| a.is_ipv6()) {
    Some(pos) => pos,
    None => { eprintln!("Skipping: no IPv6 address resolved for google.com"); return; }
};

Copy link
Copy Markdown
Contributor

@tnull tnull Mar 30, 2026

Choose a reason for hiding this comment

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

Seem like valid points? (fwiw, we should also switch to async resolution in LDK Node, cf. lightningdevkit/ldk-node#854).

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.

If you don't mind I'll take the first point, I'd like to see the second point actually manifest before silently skipping over an IPv4 or IPv6 case :)

@ldk-claude-review-bot
Copy link
Copy Markdown
Collaborator

ldk-claude-review-bot commented Mar 30, 2026

I've reviewed the full diff against the current code. The author has already addressed the tokio::net::lookup_host suggestion from my prior inline comment (the code now uses the async version at line 1124). The remaining concern about expect calls assuming dual-stack DNS was already flagged.

No new issues found beyond what was flagged in my prior review.

Summary

No new issues found. The prior review's concern about expect calls at lines 1127-1133 introducing new flakiness in environments without dual-stack DNS resolution still applies (already posted as an inline comment).

The fix is mechanically sound: dynamically resolving Google's IPs eliminates the hardcoded-address flakiness, type conversions via .into() are correct (SocketAddr is Copy, and From<SocketAddr> for SocketAddress exists), and the set_port mutation for failure cases happens after the success loop consumes copies.

@tankyleo tankyleo force-pushed the 2026-03-tor-connect-flakiness branch from 684fb30 to cbe5c61 Compare March 30, 2026 05:12
@tankyleo tankyleo requested a review from tnull March 30, 2026 05:14
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.19%. Comparing base (688544d) to head (20e943e).
⚠️ Report is 31 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4521      +/-   ##
==========================================
+ Coverage   86.14%   86.19%   +0.05%     
==========================================
  Files         160      160              
  Lines      108046   108410     +364     
  Branches   108046   108410     +364     
==========================================
+ Hits        93080    93448     +368     
+ Misses      12346    12326      -20     
- Partials     2620     2636      +16     
Flag Coverage Δ
tests 86.19% <ø> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tnull tnull removed their request for review March 30, 2026 08:31
@tankyleo tankyleo force-pushed the 2026-03-tor-connect-flakiness branch from cbe5c61 to 20e943e Compare March 30, 2026 15:44
@tankyleo tankyleo requested a review from tnull March 30, 2026 15:53
@tnull tnull merged commit 67bf852 into lightningdevkit:main Mar 31, 2026
22 of 23 checks passed
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.

test_tor_connect is flaky

4 participants