Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect use of sync.WaitGroup #23

Open
ainar-g opened this issue Nov 1, 2023 · 0 comments
Open

Incorrect use of sync.WaitGroup #23

ainar-g opened this issue Nov 1, 2023 · 0 comments

Comments

@ainar-g
Copy link
Contributor

ainar-g commented Nov 1, 2023

Caught in dnsproxy tests failures:

==================
WARNING: DATA RACE
Read at 0x00c0001823e0 by goroutine 9:
  runtime.raceread()
      <autogenerated>:1 +0x24
  github.com/ameshkov/dnscrypt/v2.(*Server).ServeTCP()
      /Users/runner/go/pkg/mod/github.com/ameshkov/dnscrypt/[email protected]/server_tcp.go:65 +0x1ea
  github.com/AdguardTeam/dnsproxy/upstream.startTestDNSCryptServer.func3()
      /Users/runner/work/dnsproxy/dnsproxy/upstream/dnscrypt_test.go:79 +0x45

Previous write at 0x00c0001823e0 by goroutine 10:
  runtime.racewrite()
      <autogenerated>:1 +0x24
  github.com/ameshkov/dnscrypt/v2.(*Server).Shutdown.func1()
      /Users/runner/go/pkg/mod/github.com/ameshkov/dnscrypt/[email protected]/server.go:139 +0x44

Goroutine 9 (running) created at:
  github.com/AdguardTeam/dnsproxy/upstream.startTestDNSCryptServer()
      /Users/runner/work/dnsproxy/dnsproxy/upstream/dnscrypt_test.go:78 +0x91b
  github.com/AdguardTeam/dnsproxy/upstream.TestDNSCrypt_Exchange_dialFail.func2()
      /Users/runner/work/dnsproxy/dnsproxy/upstream/dnscrypt_test.go:192 +0xd5
  testing.tRunner()
      /Users/runner/hostedtoolcache/go/1.20.10/x64/src/testing/testing.go:1576 +0x216
  testing.(*T).Run.func1()
      /Users/runner/hostedtoolcache/go/1.20.10/x64/src/testing/testing.go:1629 +0x47

Goroutine 10 (running) created at:
  github.com/ameshkov/dnscrypt/v2.(*Server).Shutdown()
      /Users/runner/go/pkg/mod/github.com/ameshkov/dnscrypt/[email protected]/server.go:138 +0x14e
  github.com/AdguardTeam/dnsproxy/upstream.startTestDNSCryptServer.func1()
      /Users/runner/work/dnsproxy/dnsproxy/upstream/dnscrypt_test.go:54 +0x9c
  github.com/AdguardTeam/golibs/testutil.CleanupAndRequireSuccess.func1()
      /Users/runner/go/pkg/mod/github.com/!adguard!team/[email protected]/testutil/testutil.go:216 +0x46
  testing.(*common).Cleanup.func1()
      /Users/runner/hostedtoolcache/go/1.20.10/x64/src/testing/testing.go:1150 +0x193
  testing.(*common).runCleanup()
      /Users/runner/hostedtoolcache/go/1.20.10/x64/src/testing/testing.go:1328 +0x1e9
  testing.tRunner.func2()
      /Users/runner/hostedtoolcache/go/1.20.10/x64/src/testing/testing.go:1570 +0x52
  runtime.deferreturn()
      /Users/runner/hostedtoolcache/go/1.20.10/x64/src/runtime/panic.go:476 +0x32
  testing.(*T).Run.func1()
      /Users/runner/hostedtoolcache/go/1.20.10/x64/src/testing/testing.go:1629 +0x47
==================

Which results in:

panic: sync: WaitGroup is reused before previous Wait has returned

I think that this is because s.wg.Wait() is called in a goroutine, and there is no guarantee that it will be run after all ServeTCP calls.

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

No branches or pull requests

1 participant