Enforce sequential processing of session events #4493
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.
Changes
This PR enforces sequential processing of events for the same session. Currently, when two events for the same session are processed concurrently, it's possible that session lookup will either turn up empty (initial event) or return the same previous session state for two concurrently processed events. This in turn can result in inconsistent session entries (like, for instance, two session entries for the same session_id). More detailed example race scenario this fix addresses is described at https://github.com/plausible/analytics/pull/4493/files#diff-16bb729e90786448aef27f15fce06e9d977d947389e91fdc24c0ea6760c290f6R78-R99.
TODO
with_lock!
, end at the very beginning of lock function body)Tests