Skip to content

Race condition in persistent sessions #739

@sb8244

Description

@sb8244

I believe I have found a race condition bug with persistent sessions. I think it's pretty hard to recreate in a general reproduction. Although I can give it a shot if needed. The race is pretty visible to me now:

Condition

  • Expired session
  • valid persistent session
  • Easy way to consistently reproduce is to set the TTL to something very small on the session, like 3s, with a long persistent session TTL

Reproduce Bug

  • Have 2 tabs or more of the app loaded
  • Load across these tabs
  • Eventually some of the tabs will return a 401, with one of the tabs loading correctly
  • Reloading the 401 tabs causes them to load correctly (because the user isn't actually logged out)

Suspected Issue

PowPersistentSession.Plug.Cookie.before_send_delete/2 calls expire_token_in_store. This is running after a valid authorization (sometimes? not sure of when). If 2 requests start at the same time, and one of them completes before the other one tries to auth, then the session token will be invalid.

Maybe: This would be most likely to happen if the per-domain request limit is hit, so requests are sitting in a queueing state for longer than normal.

Solution

Working on figuring out a solution for my app right now. Not sure if it will be a wider solution or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions