Skip to content

v1.12.0 race condition #968

@nicolaasuni

Description

@nicolaasuni

After upgrading to: github.com/prometheus/client_golang v1.12.0
I am getting "WARNING: DATA RACE" while testing:
https://github.com/nexmoinc/gosrvlib/tree/main/pkg/metrics/prometheus

The race conditions do not appear in version 1.11.0 or any other previous version.

The race condition do not appear when disabling the t.Parallel() in the unit tests (e.g.: https://github.com/nexmoinc/gosrvlib/blob/main/pkg/metrics/prometheus/client_test.go#L153).

The relevant errors are:

==================
WARNING: DATA RACE
Read at 0x00c000598660 by goroutine 59:
 runtime.mapaccess2_faststr()
     /usr/local/go/src/runtime/map_faststr.go:107 +0x0
 runtime/metrics.runtime_readMetrics()
     /usr/local/go/src/runtime/metrics.go:563 +0xb9
 github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1()
     /home/user/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/registry.go:446 +0x133

Previous write at 0x00c000598660 by goroutine 70:
 runtime.mapassign_faststr()
     /usr/local/go/src/runtime/map_faststr.go:202 +0x0
 runtime.initMetrics()
     /usr/local/go/src/runtime/metrics.go:67 +0x1c6
 github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1()
     /home/user/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/registry.go:446 +0x133

Goroutine 59 (running) created at:
 github.com/prometheus/client_golang/prometheus.(*Registry).Gather()
     /home/user/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/registry.go:538 +0x1137
 github.com/prometheus/client_golang/prometheus/testutil.GatherAndCount()
     /home/user/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/testutil/testutil.go:139 +0x7a
 github.com/nexmoinc/gosrvlib/pkg/metrics/prometheus.TestIncLogLevelCounter()
     /home/user/go/src/github.com/nexmoinc/gosrvlib/pkg/metrics/prometheus/client_test.go:144 +0x157
 testing.tRunner()
     /usr/local/go/src/testing/testing.go:1259 +0x22f
 testing.(*T).Run·dwrap·21()
     /usr/local/go/src/testing/testing.go:1306 +0x47

Goroutine 70 (finished) created at:
 github.com/prometheus/client_golang/prometheus.(*Registry).Gather()
     /home/user/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/registry.go:538 +0x1137
 github.com/prometheus/client_golang/prometheus/promhttp.HandlerFor.func1()
     /home/user/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/promhttp/http.go:126 +0x11a
 net/http.HandlerFunc.ServeHTTP()
     /usr/local/go/src/net/http/server.go:2047 +0x4d
 github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerInFlight.func1()
     /home/user/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/promhttp/instrument_server.go:40 +0x118
 net/http.HandlerFunc.ServeHTTP()
     /usr/local/go/src/net/http/server.go:2047 +0x4d
 github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerCounter.func1()
     /home/user/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/promhttp/instrument_server.go:117 +0xe2
 net/http.HandlerFunc.ServeHTTP()
     /usr/local/go/src/net/http/server.go:2047 +0x4d
 net/http.Handler.ServeHTTP-fm()
     /usr/local/go/src/net/http/server.go:87 +0x75
 net/http.HandlerFunc.ServeHTTP()
     /usr/local/go/src/net/http/server.go:2047 +0x4d
 github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerRequestSize.func2()
     /home/user/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/promhttp/instrument_server.go:204 +0xb3
 net/http.HandlerFunc.ServeHTTP()
     /usr/local/go/src/net/http/server.go:2047 +0x4d
 github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerResponseSize.func1()
     /home/user/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/promhttp/instrument_server.go:239 +0xec
 net/http.HandlerFunc.ServeHTTP()
     /usr/local/go/src/net/http/server.go:2047 +0x4d
 github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerCounter.func1()
     /home/user/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/promhttp/instrument_server.go:117 +0xe2
 net/http.HandlerFunc.ServeHTTP()
     /usr/local/go/src/net/http/server.go:2047 +0x4d
 github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerDuration.func2()
     /home/user/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/promhttp/instrument_server.go:84 +0xca
 net/http.HandlerFunc.ServeHTTP()
     /usr/local/go/src/net/http/server.go:2047 +0x4d
 github.com/prometheus/client_golang/prometheus/promhttp.InstrumentHandlerInFlight.func1()
     /home/user/go/pkg/mod/github.com/prometheus/[email protected]/prometheus/promhttp/instrument_server.go:40 +0x118
 net/http.HandlerFunc.ServeHTTP()
     /usr/local/go/src/net/http/server.go:2047 +0x4d
 github.com/nexmoinc/gosrvlib/pkg/metrics/prometheus.TestInstrumentHandler()
     /home/user/go/src/github.com/nexmoinc/gosrvlib/pkg/metrics/prometheus/client_test.go:89 +0x3a1
 testing.tRunner()
     /usr/local/go/src/testing/testing.go:1259 +0x22f
 testing.(*T).Run·dwrap·21()
     /usr/local/go/src/testing/testing.go:1306 +0x47
==================
=== CONT  TestInstrumentDB
   testing.go:1152: race detected during execution of test
--- FAIL: TestInstrumentDB (0.03s)
=== CONT  TestIncLogLevelCounter
   testing.go:1152: race detected during execution of test
--- FAIL: TestIncLogLevelCounter (0.04s)
=== CONT  TestInstrumentRoundTripper
   testing.go:1152: race detected during execution of test
--- FAIL: TestInstrumentRoundTripper (0.06s)
=== CONT  TestInstrumentHandler
   testing.go:1152: race detected during execution of test
--- FAIL: TestInstrumentHandler (0.07s)
FAIL

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions