Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session creation soft-lock #3188

Closed
AriDeve opened this issue Jan 24, 2025 · 3 comments
Closed

Session creation soft-lock #3188

AriDeve opened this issue Jan 24, 2025 · 3 comments
Labels
bug Something isn't working fixed in dev Fixed in the dev branch

Comments

@AriDeve
Copy link

AriDeve commented Jan 24, 2025

Describe the Bug

I have encountered an issue where, due to incorrect existence checks, a session will never be able to "send" data. Consistent attempts to create a new session when it already exists cause the send endpoint to time out instead of failing gracefully.
This happens due to multiple compounding issues:

  1. When a request to send is processed, it creates a session (or tries to create one) before any action is taken with the event. It's not exactly a problem, but can currently cause an issue due to an issue mentioned later
  2. If a sessions first action is to send session data, aka type: 'identify' event, it gets placed into the session_data table
  3. When the next event comes in, no matter the type, an attempt to check if the session already exists is made before creating it. This check uses getWebsiteSession to get an existing session. getWebsiteSession doesn't return an existing session if there isn't an entry by the session in the website_event table, meaning that due to the second point, it tries to create a new session even if it exists
  4. createSession fails due to a unique constraint error from the database, but the error is explicitly ignored, and visitId is still returned in the object. !session?.id catches that the session ID is missing, but fails to properly close the request, simply returning from send, meaning that whatever called the endpoint would timeout silently without explanation

This issue essentially soft-locks a specific session, because it cannot recover after the initial creation. A similar issue can occur as called out in the first point, if the creation of any type of event fails for unforeseen issues, as getWebsiteSession requires an entry in both session and website_event.

Potential fixes/solutions:

  1. Add a separate query for checking if a session already exists that doesn't depend on other tables. This would make point one irrelevant, as well as solve the issue at hand
  2. Don't ignore the unique constraint error, as that causes the function to return some data. However, the visitId could be used elsewhere, I haven't checked too far. Or add a proper error response for the instance, where the session doesn't contain an id, so it doesn't cause timeouts. I remember seeing someone already mention this one on Discord

Log output is from @aperion_93218 on discord, I didn't have the log on hand, but it is the same. Otherwise this issue doesn't log any errors.

Database

PostgreSQL

Relevant log output

2025-01-06 14:25:19.730 UTC [11765] ERROR:  duplicate key value violates unique constraint "session_pkey"
2025-01-06 14:25:19.730 UTC [11765] DETAIL:  Key (session_id)=(43549496-274a-571b-b209-90206c5bde86) already exists.
2025-01-06 14:25:19.730 UTC [11765] STATEMENT:  INSERT INTO "public"."session" ("session_id","website_id","hostname","browser","os","device","screen","language","country","subdivision1","subdivision2","city","created_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13) RETURNING "public"."session"."session_id", "public"."session"."website_id", "public"."session"."hostname", "public"."session"."browser", "public"."session"."os", "public"."session"."device", "public"."session"."screen", "public"."session"."language", "public"."session"."country", "public"."session"."subdivision1", "public"."session"."subdivision2", "public"."session"."city", "public"."session"."created_at"

Which Umami version are you using? (if relevant)

No response

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@mikecao mikecao added the bug Something isn't working label Jan 25, 2025
@mikecao mikecao added the fixed in dev Fixed in the dev branch label Feb 1, 2025
@szwabodev
Copy link

hello, any idea when the fix will be released?

@6mdx
Copy link

6mdx commented Feb 20, 2025

Hello, Any update?

@mikecao
Copy link
Collaborator

mikecao commented Feb 21, 2025

Fixed in v2.16.0.

@mikecao mikecao closed this as completed Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in dev Fixed in the dev branch
Projects
None yet
Development

No branches or pull requests

4 participants