decred / dcrd

Decred daemon in Go (golang).
https://decred.org
ISC License
731 stars 288 forks source link

Panic on notifying index subscribers (release 1.7.1) #2913

Closed jholdstock closed 2 years ago

jholdstock commented 2 years ago
fatal error: concurrent map iteration and map write

Full trace

https://github.com/decred/dcrd/blob/e1b2e6011bf679a36ed39494dfcb1dcac30bbc80/blockchain/indexers/common.go#L692-L695

Maybe relevant for #2871

jrick commented 2 years ago

this seems like a data race, and unrelated to the fact that the map is being modified during iteration in the loop. can you reproduce with the race detector enabled?

chappjc commented 2 years ago

Almost certainly the WaitForSync call in handleExistsAddresses. Seems like the Indexer interface needs a NotifiySubscribers to clear out the map while under lock. It's not even safe to check the length of the map... so it's not clear how to safely use the Subscribers method at all unless it returned a copy of the map.

jholdstock commented 2 years ago

Bingo - race detected

http://sprunge.us/xgwg3Y

chappjc commented 2 years ago

It is fixed in https://github.com/decred/dcrd/pull/2871 then. It introduced NotifySyncSubscribers and deprecated Subscribers. Maybe needs a backport though...

davecgh commented 2 years ago

This is fixed by #2871. However, unfortunately @dnldd implemented it in such a way that it can't be back ported to the v1.7.1 release, because it required a major module version bump. It will need to be backported in a way that doesn't break the API.

dnldd commented 2 years ago

Noted, working on it 👍