grafana / vmware_exporter

Apache License 2.0
4 stars 5 forks source link

Fix data race #27

Closed marctc closed 2 years ago

marctc commented 2 years ago

Running go test -race reports a potential race condition:

==================
WARNING: DATA RACE
Read at 0x00c00038c090 by goroutine 101:
  runtime.racereadrange()
      <autogenerated>:1 +0x1b
  github.com/grafana/vmware_exporter/vsphere.(*vsphereCollector).collectResource.func2()
      /home/marctc/workspace/vmware_exporter/vsphere/collector.go:113 +0x66

Previous write at 0x00c00038c090 by goroutine 98:
  github.com/grafana/vmware_exporter/vsphere.(*vsphereCollector).collectResource.func1()
      /home/marctc/workspace/vmware_exporter/vsphere/collector.go:111 +0x356
  github.com/grafana/vmware_exporter/vsphere.(*vsphereCollector).collectResource.func2()
      /home/marctc/workspace/vmware_exporter/vsphere/collector.go:113 +0x66

Goroutine 101 (running) created at:
  github.com/grafana/vmware_exporter/vsphere.(*vsphereCollector).collectResource()
      /home/marctc/workspace/vmware_exporter/vsphere/collector.go:106 +0xdea
  github.com/grafana/vmware_exporter/vsphere.(*vsphereCollector).Collect.func1()
      /home/marctc/workspace/vmware_exporter/vsphere/collector.go:56 +0x153
  github.com/grafana/vmware_exporter/vsphere.(*vsphereCollector).Collect.func2()
      /home/marctc/workspace/vmware_exporter/vsphere/collector.go:57 +0x66

Goroutine 98 (finished) created at:
  github.com/grafana/vmware_exporter/vsphere.(*vsphereCollector).collectResource()
      /home/marctc/workspace/vmware_exporter/vsphere/collector.go:106 +0xdea
  github.com/grafana/vmware_exporter/vsphere.(*vsphereCollector).Collect.func1()
      /home/marctc/workspace/vmware_exporter/vsphere/collector.go:56 +0x153
  github.com/grafana/vmware_exporter/vsphere.(*vsphereCollector).Collect.func2()
      /home/marctc/workspace/vmware_exporter/vsphere/collector.go:57 +0x66
==================