Skip to content

Commit

Permalink
server: fix TestServerAcceptErrorHandling data race
Browse files Browse the repository at this point in the history
    WARNING: DATA RACE
    Read at 0x00c0002a6340 by goroutine 44:
      github.com/emersion/go-smtp_test.TestServerAcceptErrorHandling()
          /home/simon/src/go-smtp/server_test.go:333 +0x6de
      testing.tRunner()
          /usr/lib/go/src/testing/testing.go:1689 +0x21e
      testing.(*T).Run.gowrap1()
          /usr/lib/go/src/testing/testing.go:1742 +0x44

    Previous write at 0x00c0002a6340 by goroutine 45:
      github.com/emersion/go-smtp_test.TestServerAcceptErrorHandling.func1()
          /home/simon/src/go-smtp/server_test.go:323 +0x64

    Goroutine 44 (running) created at:
      testing.(*T).Run()
          /usr/lib/go/src/testing/testing.go:1742 +0x825
      testing.runTests.func1()
          /usr/lib/go/src/testing/testing.go:2161 +0x85
      testing.tRunner()
          /usr/lib/go/src/testing/testing.go:1689 +0x21e
      testing.runTests()
          /usr/lib/go/src/testing/testing.go:2159 +0x8be
      testing.(*M).Run()
          /usr/lib/go/src/testing/testing.go:2027 +0xf17
      main.main()
          _testmain.go:163 +0x2bd

    Goroutine 45 (finished) created at:
      github.com/emersion/go-smtp_test.TestServerAcceptErrorHandling()
          /home/simon/src/go-smtp/server_test.go:322 +0x5d5
      testing.tRunner()
          /usr/lib/go/src/testing/testing.go:1689 +0x21e
      testing.(*T).Run.gowrap1()
          /usr/lib/go/src/testing/testing.go:1742 +0x44
  • Loading branch information
emersion committed Apr 17, 2024
1 parent 6f31b3a commit a990aa0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ func TestServerAcceptErrorHandling(t *testing.T) {
s.ErrorLog = log.New(errorLog, "", 0)

l := newFailingListener()
var serveError error
done := make(chan error, 1)
go func() {
serveError = s.Serve(l)
done <- s.Serve(l)
l.Close()
}()

Expand All @@ -330,6 +330,7 @@ func TestServerAcceptErrorHandling(t *testing.T) {
l.Send(permanentError)
s.Close()

serveError := <-done
if serveError == nil {
t.Fatal("Serve had exited without an expected error")
} else if serveError != permanentError {
Expand Down

0 comments on commit a990aa0

Please sign in to comment.