Ensure thread safety for query listener collection on native driver #4567
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.
The query listener collection is potentially accessed from multiple threads and needs to be thread safe. That is very likely the cause of: #4376
It is difficult to say for certain if that is the cause, as race condition issues don't generally produce obvious or repeatable crashes, but if you take the locks out of this PR and run the test, it'll crash hard.
For workaround in the issue, I'll comment on that in the issue in more detail. Summary, though, unless all access was in the same thread, it's still possible to have race conditions, and it looks like there are multiple threads still.
Presumably this has been an issue since this change: https://github.com/cashapp/sqldelight/pull/4148/files#diff-18eaa5efaf87c02833bc443af34a18778468fbe7e35dc9de4f01c61277593ce6R139
This is a pretty big runtime issue, so we should get a fix out, but again, it's hard to say for sure this fixes the originally observed behavior, so we'll really need to have it published and watch what happens.