sync wrapper: Clear mutex poison and provide underlying mutex guar #160
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.
Issue
Sqlite can return busy especially when multiple transactions are running concurrently. In async context with the Sync Wrapper, this will cause one client to get error (1) and panic within diesel causing the mutex to be poisoned and all subsequent clients panicking as a a result.
Cause
A busy timeout can be set and sqlite will pause waiting clients. This is set by the application but theoretically panics can still happen even with values in the order of seconds. Therefore an application could have a critical failure.
Resolution
This PR tries to recover from such situations. It includes a commit allow reproducing the issue that could be dropped if the PR is validated.
Would you have any other solutions to this issue? Or do you think this is the most we can do at the moment?
Notes
[1]
A panic is triggered because the statement iterator is
NotStarted
and doesn't contain the statement (that was consumed below).Because an error is returned during the step.
I am not sure we can recover except by retrying until getting a non-busy result. This is still not ideal because it would be blocking or with arbitrary limits.