Skip to content

Commit

Permalink
Revert "event: unlock mutex before sending event on channel"
Browse files Browse the repository at this point in the history
This change causes a data race:

```
==================
WARNING: DATA RACE
Write at 0x00c0003b6b50 by goroutine 167:
  runtime.closechan()
      /usr/local/go/src/runtime/chan.go:334 +0x0
  github.com/fsouza/go-dockerclient.(*eventMonitoringState).disableEventMonitoring()
      /code/event.go:191 +0x10e
  github.com/fsouza/go-dockerclient.(*Client).RemoveEventListener()
      /code/event.go:113 +0xd1
  github.com/fsouza/go-dockerclient.testEventListeners.func2()
      /code/event_test.go:238 +0x46
  github.com/fsouza/go-dockerclient.testEventListeners()
      /code/event_test.go:269 +0x1022
  github.com/fsouza/go-dockerclient.TestTLSEventListeners()
      /code/event_test.go:28 +0x8e
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:862 +0x163

Previous read at 0x00c0003b6b50 by goroutine 410:
  runtime.chansend()
      /usr/local/go/src/runtime/chan.go:142 +0x0
  github.com/fsouza/go-dockerclient.(*Client).eventHijack.func1()
      /code/event.go:356 +0x65d

Goroutine 167 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:913 +0x699
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:1154 +0xa8
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:862 +0x163
  testing.runTests()
      /usr/local/go/src/testing/testing.go:1152 +0x523
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:1069 +0x2eb
  main.main()
      _testmain.go:656 +0x222

Goroutine 410 (finished) created at:
  github.com/fsouza/go-dockerclient.(*Client).eventHijack()
      /code/event.go:344 +0x56a
  github.com/fsouza/go-dockerclient.(*eventMonitoringState).connectWithRetry()
      /code/event.go:255 +0xdc
  github.com/fsouza/go-dockerclient.(*eventMonitoringState).monitorEvents()
      /code/event.go:217 +0xba
==================
```

My bad x)

Related to #511.

This reverts commit a107859.
  • Loading branch information
fsouza committed Jan 20, 2019
1 parent 12fcd5d commit 3322614
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,9 @@ func (c *Client) eventHijack(startTime int64, eventChan chan *APIEvents, errChan
c.eventMonitor.RLock()
if c.eventMonitor.enabled && c.eventMonitor.C == eventChan {
// Signal that we're exiting.
c.eventMonitor.RUnlock()
eventChan <- EOFEvent
} else {
c.eventMonitor.RUnlock()
}
c.eventMonitor.RUnlock()
break
}
errChan <- err
Expand Down

0 comments on commit 3322614

Please sign in to comment.