Serialize new session cookie synchronously to avoid overlapping sessions (close #1381) #1382
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 #1381
The issue reported that after upgrading to v4, there is a higher number of very short sessions in very short sequences. The hypothesis was that this is due to the async cookie access introduced in v4.
I was able to reproduce the problem with a simple setup that I added to the integration tests – a single page that embeds 15 iframe pages. The iframes are loaded at the same time and each initializes a new tracker and tracks a page view. Since the iframes share the same cookies, we should only see a single session id across all tracked page views.
With this setup, I was getting multiple different session ids across the page views. It was usually around 10 different session IDs.
The change I made was to flush the cookies (write them synchronously) each time the session changes. That means the first session or every subsequent new session. When a new event is tracked without triggering a new session, the cookies are still updated async by default.
This fixed the problem in the iframe test setup. Now I am only getting a single session ID across all page views. Have kept this test in the integration tests so that we don't regress on the behaviour.