Take lock over Snapshotter
state during callback
#6882
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Another fix spun out of #6616.
This
Snapshotter
class has astd::mutex
member, which is locked in most of its member functions to prevent concurrent access to its member state. The one function that doesn't try to lock, issnapshot_
, the callback that comes via theThreadMessaging
system so is almost guaranteed to race with other calls. I think the reason we didn't lock there is that locking for the whole function causes a deadlock (this callback tries to.commit()
aTx
, which calls back into theSnapshotter
to work out if that should trigger another snapshot...). But that's fine, we can drop the lock while we're not accessing any member state.This isn't great, and potentially risks leaving orphaned items in the
pending_snapshots
collection? But I think the fix is worthwhile for now, until we have a better task system to work with.