srtgo icon indicating copy to clipboard operation
srtgo copied to clipboard

Running /examples/echo-receiver/main.go with the race detector reports a race condition

Open michaeljdennis opened this issue 2 years ago • 1 comments

When running the echo-receiver example with the race detector (go run -race main.go) and then starting an SRT stream, I see the following race condition reported:

WARNING: DATA RACE
Write at 0x00c00020e020 by goroutine 10:
  github.com/haivision/srtgo.(*pollDesc).reset()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/poll.go:262 +0xa5
  github.com/haivision/srtgo.SrtSocket.Read()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/read.go:43 +0x46
  main.handler()
      /home/michael/bitcentral/srt-example/main.go:38 +0xfc
  main.main.func2()
      /home/michael/bitcentral/srt-example/main.go:77 +0x44

Previous write at 0x00c00020e020 by goroutine 8:
  sync/atomic.StoreInt32()
      /usr/local/go/src/runtime/race_amd64.s:231 +0xb
  sync/atomic.StoreInt32()
      <autogenerated>:1 +0x14
  github.com/haivision/srtgo.(*pollServer).run()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/pollserver.go:100 +0x1d9
  github.com/haivision/srtgo.pollServerCtxInit.func1()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/pollserver.go:31 +0x33

Goroutine 10 (running) created at:
  main.main()
      /home/michael/bitcentral/srt-example/main.go:77 +0x315

Goroutine 8 (running) created at:
  github.com/haivision/srtgo.pollServerCtxInit()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/pollserver.go:31 +0x1bc
  sync.(*Once).doSlow()
      /usr/local/go/src/sync/once.go:74 +0xf0
  sync.(*Once).Do()
      /usr/local/go/src/sync/once.go:65 +0x44
  github.com/haivision/srtgo.pollServerCtx()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/pollserver.go:20 +0x11e
  github.com/haivision/srtgo.pollDescInit()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/poll.go:77 +0xfd
  github.com/haivision/srtgo.NewSrtSocket()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/srtgo.go:112 +0x2e9
  main.main()
      /home/michael/bitcentral/srt-example/main.go:59 +0x15c
==================
==================
WARNING: DATA RACE
Read at 0x00c00020e020 by goroutine 8:
  sync/atomic.LoadInt32()
      /usr/local/go/src/runtime/race_amd64.s:202 +0xb
  sync/atomic.LoadInt32()
      <autogenerated>:1 +0x10
  github.com/haivision/srtgo.(*pollServer).run()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/pollserver.go:100 +0x1d9
  github.com/haivision/srtgo.pollServerCtxInit.func1()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/pollserver.go:31 +0x33

Previous write at 0x00c00020e020 by goroutine 10:
  github.com/haivision/srtgo.(*pollDesc).reset()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/poll.go:262 +0xa5
  github.com/haivision/srtgo.SrtSocket.Read()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/read.go:43 +0x46
  main.handler()
      /home/michael/bitcentral/srt-example/main.go:38 +0xfc
  main.main.func2()
      /home/michael/bitcentral/srt-example/main.go:77 +0x44

Goroutine 8 (running) created at:
  github.com/haivision/srtgo.pollServerCtxInit()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/pollserver.go:31 +0x1bc
  sync.(*Once).doSlow()
      /usr/local/go/src/sync/once.go:74 +0xf0
  sync.(*Once).Do()
      /usr/local/go/src/sync/once.go:65 +0x44
  github.com/haivision/srtgo.pollServerCtx()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/pollserver.go:20 +0x11e
  github.com/haivision/srtgo.pollDescInit()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/poll.go:77 +0xfd
  github.com/haivision/srtgo.NewSrtSocket()
      /home/michael/go/pkg/mod/github.com/haivision/[email protected]/srtgo.go:112 +0x2e9
  main.main()
      /home/michael/bitcentral/srt-example/main.go:59 +0x15c

Goroutine 10 (running) created at:
  main.main()
      /home/michael/bitcentral/srt-example/main.go:77 +0x315
==================

michaeljdennis avatar Sep 21 '23 23:09 michaeljdennis

This issue seems to be handled by pull request #65.

michaeljdennis avatar Sep 22 '23 02:09 michaeljdennis