Data race in pollNetMapStream() #411

Closed
opened 2025-12-29 01:28:32 +01:00 by adam · 4 comments
Owner

Originally created by @evenh on GitHub (Jan 11, 2023).

Bug description
While chasing another bug I did enable the golang race detector. It did report a data race:

==================
WARNING: DATA RACE
Read at 0x00c0001a8a68 by goroutine 76:
  github.com/juanfont/headscale.(*Headscale).pollNetMapStream()
      /go/src/headscale/protocol_common_poll.go:611 +0x52c
  github.com/juanfont/headscale.(*Headscale).handlePollCommon()
      /go/src/headscale/protocol_common_poll.go:223 +0x14d4
  github.com/juanfont/headscale.(*ts2021App).NoisePollNetMapHandler()
      /go/src/headscale/protocol_noise_poll.go:66 +0x690
  github.com/juanfont/headscale.(*ts2021App).NoisePollNetMapHandler-fm()
      <autogenerated>:1 +0x4c
  net/http.HandlerFunc.ServeHTTP()
      /usr/local/go/src/net/http/server.go:2109 +0x48
  github.com/gorilla/mux.(*Router).ServeHTTP()
      /go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x2a4
  net/http.Handler.ServeHTTP-fm()
      <autogenerated>:1 +0x60
  golang.org/x/net/http2.(*serverConn).runHandler()
      /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:2275 +0xa4
  golang.org/x/net/http2.(*serverConn).processHeaders.func1()
      /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:1988 +0x58

Previous write at 0x00c0001a8a68 by main goroutine:
  github.com/juanfont/headscale.(*Headscale).Serve()
      /go/src/headscale/app.go:739 +0x198c
  github.com/juanfont/headscale/cmd/headscale/cli.glob..func31()
      /go/src/headscale/cmd/headscale/cli/server.go:24 +0x88
  github.com/spf13/cobra.(*Command).execute()
      /go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:920 +0x854
  github.com/spf13/cobra.(*Command).ExecuteC()
      /go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:1044 +0x4ac
  github.com/spf13/cobra.(*Command).Execute()
      /go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:968 +0x38
  github.com/juanfont/headscale/cmd/headscale/cli.Execute()
      /go/src/headscale/cmd/headscale/cli/root.go:96 +0x20
  main.main()
      /go/src/headscale/cmd/headscale/headscale.go:42 +0x290
Goroutine 76 (running) created at:
  golang.org/x/net/http2.(*serverConn).processHeaders()
      /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:1988 +0x9f8
  golang.org/x/net/http2.(*serverConn).processFrame()
      /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:1487 +0x364
  golang.org/x/net/http2.(*serverConn).processFrameFromReader()
      /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:1430 +0x288
  golang.org/x/net/http2.(*serverConn).serve()
      /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:921 +0xfa4
  golang.org/x/net/http2.(*Server).ServeConn()
      /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:504 +0x116c
  golang.org/x/net/http2/h2c.h2cHandler.ServeHTTP()
      /go/pkg/mod/golang.org/x/net@v0.2.0/http2/h2c/h2c.go:97 +0x590
  golang.org/x/net/http2/h2c.(*h2cHandler).ServeHTTP()
      <autogenerated>:1 +0x64
  net/http.serverHandler.ServeHTTP()
      /usr/local/go/src/net/http/server.go:2947 +0x500
  net/http.(*conn).serve()
      /usr/local/go/src/net/http/server.go:1991 +0x8c8
  net/http.(*Server).Serve.func3()
      /usr/local/go/src/net/http/server.go:3102 +0x4c

To Reproduce
Build main at 6c714e88eecac38c36011c0f721c02eb49a5783f with CGO_ENABLED=1 and the -race build flag.

Context info

headscale @ 6c714e88eecac38c36011c0f721c02eb49a5783f.
macOS 13.1 (22C65), arm64,

Originally created by @evenh on GitHub (Jan 11, 2023). <!-- Headscale is a multinational community across the globe. Our common language is English. Please consider raising the bug report in this language. --> **Bug description** While chasing another bug I did enable the golang race detector. It did report a data race: ``` ================== WARNING: DATA RACE Read at 0x00c0001a8a68 by goroutine 76: github.com/juanfont/headscale.(*Headscale).pollNetMapStream() /go/src/headscale/protocol_common_poll.go:611 +0x52c github.com/juanfont/headscale.(*Headscale).handlePollCommon() /go/src/headscale/protocol_common_poll.go:223 +0x14d4 github.com/juanfont/headscale.(*ts2021App).NoisePollNetMapHandler() /go/src/headscale/protocol_noise_poll.go:66 +0x690 github.com/juanfont/headscale.(*ts2021App).NoisePollNetMapHandler-fm() <autogenerated>:1 +0x4c net/http.HandlerFunc.ServeHTTP() /usr/local/go/src/net/http/server.go:2109 +0x48 github.com/gorilla/mux.(*Router).ServeHTTP() /go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x2a4 net/http.Handler.ServeHTTP-fm() <autogenerated>:1 +0x60 golang.org/x/net/http2.(*serverConn).runHandler() /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:2275 +0xa4 golang.org/x/net/http2.(*serverConn).processHeaders.func1() /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:1988 +0x58 Previous write at 0x00c0001a8a68 by main goroutine: github.com/juanfont/headscale.(*Headscale).Serve() /go/src/headscale/app.go:739 +0x198c github.com/juanfont/headscale/cmd/headscale/cli.glob..func31() /go/src/headscale/cmd/headscale/cli/server.go:24 +0x88 github.com/spf13/cobra.(*Command).execute() /go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:920 +0x854 github.com/spf13/cobra.(*Command).ExecuteC() /go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:1044 +0x4ac github.com/spf13/cobra.(*Command).Execute() /go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:968 +0x38 github.com/juanfont/headscale/cmd/headscale/cli.Execute() /go/src/headscale/cmd/headscale/cli/root.go:96 +0x20 main.main() /go/src/headscale/cmd/headscale/headscale.go:42 +0x290 Goroutine 76 (running) created at: golang.org/x/net/http2.(*serverConn).processHeaders() /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:1988 +0x9f8 golang.org/x/net/http2.(*serverConn).processFrame() /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:1487 +0x364 golang.org/x/net/http2.(*serverConn).processFrameFromReader() /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:1430 +0x288 golang.org/x/net/http2.(*serverConn).serve() /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:921 +0xfa4 golang.org/x/net/http2.(*Server).ServeConn() /go/pkg/mod/golang.org/x/net@v0.2.0/http2/server.go:504 +0x116c golang.org/x/net/http2/h2c.h2cHandler.ServeHTTP() /go/pkg/mod/golang.org/x/net@v0.2.0/http2/h2c/h2c.go:97 +0x590 golang.org/x/net/http2/h2c.(*h2cHandler).ServeHTTP() <autogenerated>:1 +0x64 net/http.serverHandler.ServeHTTP() /usr/local/go/src/net/http/server.go:2947 +0x500 net/http.(*conn).serve() /usr/local/go/src/net/http/server.go:1991 +0x8c8 net/http.(*Server).Serve.func3() /usr/local/go/src/net/http/server.go:3102 +0x4c ``` **To Reproduce** Build main at `6c714e88eecac38c36011c0f721c02eb49a5783f` with `CGO_ENABLED=1` and the `-race` build flag. <!-- Steps to reproduce the behavior. --> **Context info** headscale @ `6c714e88eecac38c36011c0f721c02eb49a5783f`. macOS 13.1 (22C65), arm64,
adam added the stalebug labels 2025-12-29 01:28:32 +01:00
adam closed this issue 2025-12-29 01:28:32 +01:00
Author
Owner

@kradalby commented on GitHub (Jan 17, 2023):

curious, is this not present if CGO_ENABLED=0, or was that the options you ran with as you tested?

@kradalby commented on GitHub (Jan 17, 2023): curious, is this not present if `CGO_ENABLED=0`, or was that the options you ran with as you tested?
Author
Owner

@evenh commented on GitHub (Jan 17, 2023):

CGO_ENABLED=0 was required in order to run the race detector.

@evenh commented on GitHub (Jan 17, 2023): `CGO_ENABLED=0` was required in order to run the race detector.
Author
Owner

@github-actions[bot] commented on GitHub (Sep 26, 2023):

This issue is stale because it has been open for 180 days with no activity.

@github-actions[bot] commented on GitHub (Sep 26, 2023): This issue is stale because it has been open for 180 days with no activity.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 11, 2023):

This issue was closed because it has been inactive for 14 days since being marked as stale.

@github-actions[bot] commented on GitHub (Oct 11, 2023): This issue was closed because it has been inactive for 14 days since being marked as stale.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#411