fleet/server
Zach Wasserman 8723b83039
Fix data race in inmem query results test (#1369)
Missed locking caused a race condition detected with the --race flag:

```
==================
WARNING: DATA RACE
Read at 0x00c0004b2cf0 by goroutine 67:
  runtime.mapaccess2_fast64()
      /usr/local/Cellar/go/1.16.5/libexec/src/runtime/map_fast64.go:52 +0x0
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).WriteResult()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:37 +0x84
  github.com/fleetdm/fleet/v4/server/service.(*Service).ingestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery.go:1020 +0x258
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQueryRecordCompletionError()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1499 +0x61c
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202

Previous write at 0x00c0004b2cf0 by goroutine 104:
  runtime.mapassign_fast64()
      /usr/local/Cellar/go/1.16.5/libexec/src/runtime/map_fast64.go:92 +0x0
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).getChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:31 +0x1a4
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).ReadChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:53 +0x64
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQueryRecordCompletionError.func1()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1493 +0x117

Goroutine 67 (running) created at:
  testing.(*T).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1238 +0x5d7
  testing.runTests.func1()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1511 +0xa6
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
  testing.runTests()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1509 +0x612
  testing.(*M).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1417 +0x3b3
  main.main()
      _testmain.go:303 +0x236

Goroutine 104 (running) created at:
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQueryRecordCompletionError()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1492 +0x558
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
==================
==================
WARNING: DATA RACE
Read at 0x00c0000ff2d8 by goroutine 67:
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).WriteResult()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:37 +0xa4
  github.com/fleetdm/fleet/v4/server/service.(*Service).ingestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery.go:1020 +0x258
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQueryRecordCompletionError()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1499 +0x61c
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202

Previous write at 0x00c0000ff2d8 by goroutine 104:
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).getChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:31 +0x1bc
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).ReadChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:53 +0x64
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQueryRecordCompletionError.func1()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1493 +0x117

Goroutine 67 (running) created at:
  testing.(*T).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1238 +0x5d7
  testing.runTests.func1()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1511 +0xa6
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
  testing.runTests()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1509 +0x612
  testing.(*M).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1417 +0x3b3
  main.main()
      _testmain.go:303 +0x236

Goroutine 104 (running) created at:
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQueryRecordCompletionError()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1492 +0x558
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
==================
--- FAIL: TestIngestDistributedQueryRecordCompletionError (0.01s)
    service_osquery_test.go:1502: PASS:	QueryCompletedByHost(string,uint)
    testing.go:1092: race detected during execution of test
==================
WARNING: DATA RACE
Read at 0x00c0000f8570 by goroutine 70:
  runtime.mapaccess2_fast64()
      /usr/local/Cellar/go/1.16.5/libexec/src/runtime/map_fast64.go:52 +0x0
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).WriteResult()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:37 +0x84
  github.com/fleetdm/fleet/v4/server/service.(*Service).ingestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery.go:1020 +0x258
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1530 +0x5bc
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202

Previous write at 0x00c0000f8570 by goroutine 71:
  runtime.mapassign_fast64()
      /usr/local/Cellar/go/1.16.5/libexec/src/runtime/map_fast64.go:92 +0x0
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).getChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:31 +0x1a4
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).ReadChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:53 +0x64
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQuery.func1()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1524 +0x117

Goroutine 70 (running) created at:
  testing.(*T).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1238 +0x5d7
  testing.runTests.func1()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1511 +0xa6
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
  testing.runTests()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1509 +0x612
  testing.(*M).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1417 +0x3b3
  main.main()
      _testmain.go:303 +0x236

Goroutine 71 (running) created at:
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1523 +0x4f4
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
==================
==================
WARNING: DATA RACE
Read at 0x00c000c480d8 by goroutine 70:
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).WriteResult()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:37 +0xa4
  github.com/fleetdm/fleet/v4/server/service.(*Service).ingestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery.go:1020 +0x258
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1530 +0x5bc
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202

Previous write at 0x00c000c480d8 by goroutine 71:
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).getChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:31 +0x1bc
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).ReadChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:53 +0x64
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQuery.func1()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1524 +0x117

Goroutine 70 (running) created at:
  testing.(*T).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1238 +0x5d7
  testing.runTests.func1()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1511 +0xa6
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
  testing.runTests()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1509 +0x612
  testing.(*M).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1417 +0x3b3
  main.main()
      _testmain.go:303 +0x236

Goroutine 71 (running) created at:
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1523 +0x4f4
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
==================
--- FAIL: TestIngestDistributedQuery (0.01s)
    service_osquery_test.go:1532: PASS:	QueryCompletedByHost(string,uint)
    testing.go:1092: race detected during execution of test
FAIL
FAIL	github.com/fleetdm/fleet/v4/server/service	42.743s
```
2021-07-13 12:27:41 -07:00
..
authz Add v4 suffix in go.mod (#1224) 2021-06-25 21:46:51 -07:00
bindata Allow import of github.com/kolide/fleet (#2213) 2020-03-29 19:22:04 -07:00
config Reduce default session duration to 4 hours (#981) 2021-06-06 18:28:47 -07:00
contexts Add v4 suffix in go.mod (#1224) 2021-06-25 21:46:51 -07:00
datastore Disable user sso_enable if org is disabling sso (#1331) 2021-07-09 13:12:21 -03:00
fleet Return a distinct error when the auth header is not available vs when it's bad (#1294) 2021-07-05 10:17:31 -03:00
health Fix documentation typos (#1682) 2017-12-21 18:37:32 -08:00
launcher Add v4 suffix in go.mod (#1224) 2021-06-25 21:46:51 -07:00
live_query Add v4 suffix in go.mod (#1224) 2021-06-25 21:46:51 -07:00
logging Fix Kinesis/Firehose error messages (#1316) 2021-07-12 10:18:02 -07:00
mail Add v4 suffix in go.mod (#1224) 2021-06-25 21:46:51 -07:00
mock Add v4 suffix in go.mod (#1224) 2021-06-25 21:46:51 -07:00
ptr Agent options added to organization settings (#1120) 2021-06-17 13:47:15 -07:00
pubsub Fix data race in inmem query results test (#1369) 2021-07-13 12:27:41 -07:00
service When creating a pack store team, host, and label ids provided (#1332) 2021-07-12 10:48:50 -03:00
sso Add v4 suffix in go.mod (#1224) 2021-06-25 21:46:51 -07:00
test Add v4 suffix in go.mod (#1224) 2021-06-25 21:46:51 -07:00
websocket Add v4 suffix in go.mod (#1224) 2021-06-25 21:46:51 -07:00