Commit 15f46cc
fix: prevent GC finalizer from closing TCP conn in p2p switch tests (#2805)
## Summary
- Fix flaky `TestPeerRemovedFromReactorOnStopWithNilReason` and
`TestSwitchInitPeerIsNotCalledBeforeRemovePeer` tests by retaining the
`net.Conn` returned by `rp.Dial()` instead of discarding it
- When the connection was discarded (`_, err = rp.Dial(...)`), Go's GC
finalizer on `netFD` could close the TCP socket, causing the switch's
MConnection to receive EOF and immediately remove the peer before the
test could observe it
- Reproduced locally: ~2-4% failure rate with `-race`, 0% without
`-race`; 0% failure rate after fix across 100+ race-enabled runs
Closes #2804
## Test plan
- [x] `go test -v -race -run
"TestPeerRemovedFromReactorOnStopWithNilReason|TestSwitchInitPeerIsNotCalledBeforeRemovePeer"
-count=100 -timeout=5m ./p2p/` passes (0 failures out of 200 test runs)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent b91224a commit 15f46cc
1 file changed
+6
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
819 | 819 | | |
820 | 820 | | |
821 | 821 | | |
822 | | - | |
| 822 | + | |
823 | 823 | | |
| 824 | + | |
824 | 825 | | |
825 | 826 | | |
826 | 827 | | |
| |||
832 | 833 | | |
833 | 834 | | |
834 | 835 | | |
835 | | - | |
| 836 | + | |
836 | 837 | | |
| 838 | + | |
837 | 839 | | |
838 | 840 | | |
839 | 841 | | |
| |||
867 | 869 | | |
868 | 870 | | |
869 | 871 | | |
870 | | - | |
| 872 | + | |
871 | 873 | | |
| 874 | + | |
872 | 875 | | |
873 | 876 | | |
874 | 877 | | |
| |||
0 commit comments