Skip to content

Deadlock with redis #185

@thorstenfleischmann

Description

@thorstenfleischmann

I experience deadlocks when having a lot of parallel requests.

With set $session_redis_pool_size 1 I can reproduce it always with just two requests.

The code is basically:

session:open()
dosomething()
session:close()

With some debug logs I think I figured out the reason.

  1. request 1 opens/locks session
  2. request 1 "open" puts connect back to pool ("set_keepalive")
  3. requests 1 does something
  4. requests 2 comes in and opens connection to redis pool. session is locked so it trys to aquire lock which takes time to time out
  5. request 1 did something and wants to close session. session:close cannot get a connection to unlock because requests 2 blocks the session waiting for the lock

Is there a good way to prevent this?

I am using lua resty session 3.

With a bigger pool size there are factors which makes the deadlock more or less likely. It looks like http2 is a factor since there can be more parallel client connections.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions