appcanary / agent

The Appcanary agent
https://www.appcanary.com
GNU General Public License v3.0
47 stars 6 forks source link

fix data race in file.go / client.go heartbeat json marshal #46

Closed phillmv closed 8 years ago

phillmv commented 9 years ago
=== RUN TestHeartbeat
==================
WARNING: DATA RACE
Read by goroutine 21:
  reflect.Value.Bool()
      /usr/local/Cellar/go/1.4/libexec/src/reflect/value.go:242 +0x4d
  encoding/json.boolEncoder()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:478 +0x6e
  encoding/json.(*structEncoder).encode()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:584 +0x35b
  encoding/json.*structEncoder.(encoding/json.encode)·fm()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:598 +0x65
  encoding/json.(*ptrEncoder).encode()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:706 +0x11a
  encoding/json.*ptrEncoder.(encoding/json.encode)·fm()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:711 +0x65
  encoding/json.(*arrayEncoder).encode()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:687 +0x148
  encoding/json.*arrayEncoder.(encoding/json.encode)·fm()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:694 +0x65
  encoding/json.(*sliceEncoder).encode()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:664 +0xd6
  encoding/json.*sliceEncoder.(encoding/json.encode)·fm()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:673 +0x65
  encoding/json.(*mapEncoder).encode()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:619 +0x397
  encoding/json.*mapEncoder.(encoding/json.encode)·fm()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:629 +0x65
  encoding/json.(*encodeState).reflectValue()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:299 +0x7f
  encoding/json.(*encodeState).marshal()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:270 +0x103
  encoding/json.Marshal()
      /usr/local/Cellar/go/1.4/libexec/src/encoding/json/encode.go:135 +0xdb
  github.com/stateio/canary-agent/agent.(*CanaryClient).Heartbeat()
      /Users/phillmv/code/go/src/github.com/stateio/canary-agent/agent/client.go:42 +0x114
  github.com/stateio/canary-agent/agent.(*ClientTestSuite).TestHeartbeat()
      /Users/phillmv/code/go/src/github.com/stateio/canary-agent/agent/client_test.go:78 +0x2d2
  runtime.call16()
      /usr/local/Cellar/go/1.4/libexec/src/runtime/asm_amd64.s:401 +0x44
  reflect.Value.Call()
      /usr/local/Cellar/go/1.4/libexec/src/reflect/value.go:296 +0xd8
  github.com/stateio/testify/suite.func·003()
      /Users/phillmv/code/go/src/github.com/stateio/testify/suite/suite.go:94 +0x32c
  testing.tRunner()
      /usr/local/Cellar/go/1.4/libexec/src/testing/testing.go:447 +0x133

Previous write by goroutine 22:
  github.com/stateio/canary-agent/agent/models.(*WatchedFile).SetBeingWatched()
      /Users/phillmv/code/go/src/github.com/stateio/canary-agent/agent/models/file.go:81 +0x50
  github.com/stateio/canary-agent/agent/models.(*WatchedFile).scan()
      /Users/phillmv/code/go/src/github.com/stateio/canary-agent/agent/models/file.go:107 +0x6d
  github.com/stateio/canary-agent/agent/models.(*WatchedFile).listen()
      /Users/phillmv/code/go/src/github.com/stateio/canary-agent/agent/models/file.go:92 +0x4d

Goroutine 21 (running) created at:
  testing.RunTests()
      /usr/local/Cellar/go/1.4/libexec/src/testing/testing.go:555 +0xd4e
  github.com/stateio/testify/suite.Run()
      /Users/phillmv/code/go/src/github.com/stateio/testify/suite/suite.go:102 +0x797
  github.com/stateio/canary-agent/agent.TestClient()
      /Users/phillmv/code/go/src/github.com/stateio/canary-agent/agent/client_test.go:31 +0x76
  testing.tRunner()
      /usr/local/Cellar/go/1.4/libexec/src/testing/testing.go:447 +0x133

Goroutine 22 (running) created at:
  github.com/stateio/canary-agent/agent/models.(*WatchedFile).StartListener()
      /Users/phillmv/code/go/src/github.com/stateio/canary-agent/agent/models/file.go:62 +0x9d
  github.com/stateio/canary-agent/agent/models.NewWatchedFileWithHook()
      /Users/phillmv/code/go/src/github.com/stateio/canary-agent/agent/models/file.go:35 +0x5c
  github.com/stateio/canary-agent/agent.(*ClientTestSuite).SetupTest()
      /Users/phillmv/code/go/src/github.com/stateio/canary-agent/agent/client_test.go:43 +0x11d
  github.com/stateio/testify/suite.func·003()
      /Users/phillmv/code/go/src/github.com/stateio/testify/suite/suite.go:86 +0x10f
  testing.tRunner()
      /usr/local/Cellar/go/1.4/libexec/src/testing/testing.go:447 +0x133
==================
D0614 18:16:42.27197 33295 client.go:135] Request: POST http://127.0.0.1:60810/api/v1/agent/heartbeat/server uuid
D0614 18:16:42.274448 33295 client.go:63] Heartbeat: 0001-01-01 00:00:00 +0000 UTC
D0614 18:16:42.27455 33295 file.go:67] No longer listening to: /Users/phillmv/code/go/src/github.com/stateio/canary-agent/test/data/test.conf
--- PASS: TestHeartbeat (0.51s)
=== RUN TestSendFile
D0614 18:16:42.275987 33295 client.go:135] Request: PUT http://127.0.0.1:60812/api/v1/agent/servers/server uuid
--- PASS: TestSendFile (0.00s)
--- PASS: TestClient (0.53s)
PASS
ok      github.com/stateio/canary-agent/agent
phillmv commented 8 years ago

We definitely do not have any more data races left.