Conversation
|
I think there are two ways to solve this issue:
I think 2. might be a cleaner approach here |
| wg sync.WaitGroup | ||
| mu sync.Mutex | ||
| processingSources map[string]*ProcessingSource | ||
| processingSourcesMutex sync.RWMutex |
|
That line is the only place where we create new entries in the map. All other places just assign to properties of an entry in the map. Would a sync.Map make any difference in that case? |
|
From a low level perspective there should be no difference between creating new entry and modifying existing one, in both cases we are writing to a map. In Go concurrent writes or writes/reads are not thread safe, only concurrent reading is thread safe. Having sync.Map is one way of making the whole process thread safe. |
|
Isn't there a difference between writing to the Map structure itself, i.e. creating or deleting records and modifying the data of those records? Regardless, sync.Map is probably the right way to go judging from this paragraph from the documentation:
I can update the PR to use that instead. |
|
Actually, nvm. Dropping the type safety seems like a terrible idea. I instead went ahead and added proper read locks to the rest of the code. To clarify my point above: will be a write to the map but is just a read in the map but then modifying the contents of the entry. |
|
Thanks for fixing this! |
Looking at the logs in #21 it seems that the problematic access is hashr.go:324. This PR adds a mutex to that access. I don't know if this really is the best way to solve this but with this patch I am no longer seeing the crash.