Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race between GUI and hub in generateHashIDs. #374

Closed
davecgh opened this issue Sep 15, 2023 · 1 comment · Fixed by #402
Closed

Race between GUI and hub in generateHashIDs. #374

davecgh opened this issue Sep 15, 2023 · 1 comment · Fixed by #402

Comments

@davecgh
Copy link
Member

davecgh commented Sep 15, 2023

Running on top of PR #371 for the purposes of the matching up the line numbers, but it's the same on master.

WARNING: DATA RACE
Read at 0x00c0000e8e48 by goroutine 41:
  github.com/decred/dcrpool/pool.(*Endpoint).generateHashIDs()
      src/github.com/decred/dcrpool/pool/endpoint.go:225 +0x1d5
  github.com/decred/dcrpool/pool.(*Hub).FetchHashData()
      src/github.com/decred/dcrpool/pool/hub.go:655 +0x178
  github.com/decred/dcrpool/pool.(*Hub).FetchHashData-fm()
      <autogenerated>:1 +0x33
  github.com/decred/dcrpool/internal/gui.(*GUI).updateCacheAndNotifyWebsocketClients()
      src/github.com/decred/dcrpool/internal/gui/gui.go:316 +0xb38
  github.com/decred/dcrpool/internal/gui.(*GUI).Run.func2()
      src/github.com/decred/dcrpool/internal/gui/gui.go:395 +0x4f

Previous write at 0x00c0000e8e48 by goroutine 94:
  github.com/decred/dcrpool/pool.(*Client).handleAuthorizeRequest()
      src/github.com/decred/dcrpool/pool/client.go:271 +0xc64
  github.com/decred/dcrpool/pool.(*Client).process()
      src/github.com/decred/dcrpool/pool/client.go:842 +0x4fe
  github.com/decred/dcrpool/pool.(*Client).run.func2()
      src/github.com/decred/dcrpool/pool/client.go:1299 +0x33

Goroutine 41 (running) created at:
  github.com/decred/dcrpool/internal/gui.(*GUI).Run()
      src/github.com/decred/dcrpool/internal/gui/gui.go:394 +0x244
  main.realMain.func5()
      src/github.com/decred/dcrpool/dcrpool.go:223 +0x4f

Goroutine 94 (running) created at:
  github.com/decred/dcrpool/pool.(*Client).run()
      src/github.com/decred/dcrpool/pool/client.go:1298 +0x1bc
  github.com/decred/dcrpool/pool.(*Endpoint).connect.func3()
      src/github.com/decred/dcrpool/pool/endpoint.go:196 +0x33
@davecgh
Copy link
Member Author

davecgh commented Sep 15, 2023

The culprit is that generateHashIDs accesses the account field of clients under the endpoint's client mutex:

	e.clientsMtx.Lock()
	defer e.clientsMtx.Unlock()
...
	for _, c := range e.clients {
		hashID := hashDataID(c.account, c.extraNonce1)
		ids[hashID] = struct{}{}
	}

But then handleAuthorizeRequest in client.go sets it without a mutex:

...
		c.account = account.UUID
		c.name = name

	case true:
		// Set a default account id.
		c.account = defaultAccountID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant