Skip to content

Fix intermittent unit test failures#780

Merged
adrianosela merged 1 commit intopion:masterfrom
adrianosela:intermittent-test-failures
Jan 21, 2026
Merged

Fix intermittent unit test failures#780
adrianosela merged 1 commit intopion:masterfrom
adrianosela:intermittent-test-failures

Conversation

@adrianosela
Copy link
Copy Markdown
Contributor

@adrianosela adrianosela commented Jan 20, 2026

Fix intermittent unit test failures

Fixes two intermittent test failures caused by race conditions and resource leaks:

TestNetTest bug on pipeConn goroutine leak (conn_test.go:208, 225-228):

  • Made resultCh buffered to prevent goroutine blocking
  • Added cleanup to read from channel and close client connection when server handshake fails, preventing goroutine leak
--- FAIL: TestNetTest (60.77s)
    --- FAIL: TestNetTest/PingPong (60.03s)
        conntest.go:56: test timed out; terminating pipe
        conntest.go:130: unexpected Close error: dtls fatal: conn is closed
FAIL
--- FAIL: TestNetTest (60.84s)
    --- FAIL: TestNetTest/BasicIO (60.04s)
        conntest.go:56: test timed out; terminating pipe
        conntest.go:86: unexpected c2.Close error: dtls fatal: conn is closed
FAIL

Tested before and after with go test -run 'TestNetTest*' -v -count 20

Before failed 4/20 times, after none.

TestPSKServerKeyExchange data race (conn_test.go:806-865):

  • Changed gotServerKeyExchange from bool to atomic.Bool to eliminate data race between callback goroutine and test goroutine
  • Explicitly captured test case variables to prevent closure issues
  • Read atomic value immediately after handshake completes, before closing connections, to avoid timing-dependent failures
  === RUN   TestPSKServerKeyExchange/Server_Not_Identity_Set
  conn_test.go:855:
  Error Trace:    /home/runner/work/dtls/dtls/conn_test.go:855
  Error:          Not equal:
  expected: false
  actual  : true
  Test:           TestPSKServerKeyExchange/Server_Not_Identity_Set

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.68%. Comparing base (c6db81b) to head (1ad967d).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #780      +/-   ##
==========================================
+ Coverage   81.61%   81.68%   +0.06%     
==========================================
  Files         105      105              
  Lines        5837     5837              
==========================================
+ Hits         4764     4768       +4     
+ Misses        689      686       -3     
+ Partials      384      383       -1     
Flag Coverage Δ
go 81.68% <ø> (+0.06%) ⬆️

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.

@adrianosela adrianosela force-pushed the intermittent-test-failures branch 2 times, most recently from f37ea89 to b579e32 Compare January 20, 2026 20:39
@adrianosela adrianosela requested a review from theodorsm January 20, 2026 20:46
@adrianosela adrianosela force-pushed the intermittent-test-failures branch from b579e32 to 374503e Compare January 20, 2026 23:57
@adrianosela adrianosela requested a review from JoTurk January 20, 2026 23:57
@adrianosela adrianosela force-pushed the intermittent-test-failures branch from 374503e to 317672f Compare January 21, 2026 00:12
Fix two intermittent test failures caused by race conditions and
resource leaks:

pipeConn goroutine leak (conn_test.go:208, 225-228):
  - Made resultCh buffered to prevent goroutine blocking
  - Added cleanup to read from channel and close client connection
    when server handshake fails, preventing goroutine leak

TestPSKServerKeyExchange data race (conn_test.go:806-865):
  - Changed gotServerKeyExchange from bool to atomic.Bool to
    eliminate data race between callback goroutine and test goroutine
  - Explicitly captured test case variables to prevent closure issues
  - Read atomic value immediately after handshake completes, before
    closing connections, to avoid timing-dependent failures
@adrianosela adrianosela force-pushed the intermittent-test-failures branch from 317672f to 1ad967d Compare January 21, 2026 00:19
@adrianosela
Copy link
Copy Markdown
Contributor Author

Just running the tests a few times to make sure these errors don't appear again in CI (as I only tested on my macbook).

@adrianosela adrianosela merged commit 8ea3afc into pion:master Jan 21, 2026
37 checks passed
@adrianosela adrianosela deleted the intermittent-test-failures branch January 21, 2026 00:28
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.

2 participants