Skip to content

Conversation

@alexwlchan
Copy link
Member

@alexwlchan alexwlchan commented Sep 30, 2025

TestBreakWatcherConnRecv has been flaky for a while (#17355), which you can reliably reproduce locally with golang.org/x/tools/cmd/stress.

There's a TODO comment in those tests: "use memnet and synctest". Rewriting the test to use both of those seems to fix the flakiness. I've done 150,000 runs locally with no failures, where previously the tests would fail within a few hundred runs. The test also seems to run a lot faster now. 💪

I recommend reviewing the commits separately – the memnet changes are much easier to read in their own commit. I'll squash them into a single commit when I merge.

Updates #17355

@change-visibility-bot change-visibility-bot bot requested a review from a team September 30, 2025 08:38
@alexwlchan alexwlchan changed the title derp/derphttp: de-flake TestBreakWatcherConnRecv with memnet and synctst derp/derphttp: de-flake TestBreakWatcherConnRecv with memnet and synctest Sep 30, 2025
@alexwlchan
Copy link
Member Author

Okay, so this doesn't fully fix it, but the data race now reproduces reliably locally, where previously it was flaky:

./tool/go test ./derp/derphttp/ -run=TestBreakWatcherConnRecv -race

Progress!

@bradfitz
Copy link
Member

Exciting!

@alexwlchan
Copy link
Member Author

I think the data race is fixed, so this is ready for review. ✨

@mikeodr
Copy link
Contributor

mikeodr commented Oct 1, 2025

This is awesome thanks! ✨

@alexwlchan alexwlchan force-pushed the alexc/use-memtest-in-derphttp-test branch from 2365a1c to 9912ebb Compare October 1, 2025 15:06
@change-visibility-bot change-visibility-bot bot requested a review from a team October 1, 2025 15:06
@alexwlchan
Copy link
Member Author

Pushed a new commit which uses SetURLDialer.

Copy link
Member

@bradfitz bradfitz left a comment

Choose a reason for hiding this comment

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

LGTM otherwise!

Copy link
Member

@bradfitz bradfitz left a comment

Choose a reason for hiding this comment

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

Can you also reorder or squash the commits so there's no point in the git history where there are failing tests?

You might be able to use tstest.WhileTestRunningLogger to the data race too.

@alexwlchan
Copy link
Member Author

Can you also reorder or squash the commits so there's no point in the git history where there are failing tests?

Yup, that's the plan, but I thought all the indentation changes in the synctest commit could make the other changes harder to review, so I split them out pre-merging.

Using memnet and synctest removes flakiness caused by real networking
and subtle timing differences.

Additionally, remove the `t.Logf` call inside the server's shutdown
goroutine that was causing a false positive data race detection.

The race detector is flagging a double write during this `t.Logf` call.
This is a common pattern, noted in golang/go#40343 and elsehwere in
this file, where using `t.Logf` after a test has finished can interact
poorly with the test runner.

This is a long-standing issue which became more common after rewriting
this test to use memnet and synctest.

Fixed #17355

Signed-off-by: Alex Chan <alexc@tailscale.com>
@alexwlchan alexwlchan force-pushed the alexc/use-memtest-in-derphttp-test branch from 9912ebb to 6ef3f5e Compare October 1, 2025 15:19
@change-visibility-bot change-visibility-bot bot requested a review from a team October 1, 2025 15:19
@alexwlchan alexwlchan merged commit 7dfa267 into main Oct 2, 2025
58 checks passed
@alexwlchan alexwlchan deleted the alexc/use-memtest-in-derphttp-test branch October 2, 2025 07:38
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.

3 participants