PostHog / plugin-server

Service to process and save PostHog events, supporting JS/TS plugins at that
https://posthog.com
8 stars 5 forks source link

Handle moveDistinctIds race conditions #524

Closed yakkomajuri closed 3 years ago

yakkomajuri commented 3 years ago

Changes

Me and @macobo will probably discuss this a bit further tomorrow.

Handles 2 types of race conditions that may arise when running mergeDistinctIds:

These happen because in between the time the persons are fetched and moveDistinctIds is called, another thread may have deleted either of the persons. Happy to explain further.

Checklist

yakkomajuri commented 3 years ago

Changing the approach from the "inline alias" required adding totalMergeAttempts to alias so we can bail out of what could under very rare and specific circumstances be an infinite loop. Also not super clean :D

Also had moved towards moveDistinctIds returning a success status but I think the explicit RaceConditionError makes sense here

yakkomajuri commented 3 years ago

@macobo this should be good for a second look

yakkomajuri commented 3 years ago

I really should put some effort into deflaking these tests ðŸ˜