Skip to content

BUG: Session cache with PDO backend is deadlock prone #3519

@martinlipp

Description

@martinlipp

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Writing two different keys simultaneously into the session cache, can lead to a sql deadlock (when using a PDO backend for the Flow_Session_Storage cache).

Expected Behavior

The cache writing should be in such a way, that the possibility of deadlocks is as small as possible.

Steps To Reproduce

It is hard to reproduce reliably, since it depends on the current cache contents.

Environment

- Flow: 8.4
- PHP: 8.3

Anything else?

This is happening because the keys used for Session cache entries are in large parts not unique enough.
See

$this->storageCache->set($this->storageIdentifier . md5($key), $data, [$this->storageIdentifier], 0);

For the key $this->storageIdentifier . md5($key) is used. The first part ($this->storageIdentifier) is always the same for the same Session. This can lead to deadlocks, while the database is trying to insert the index for the new entry (since the probability that the index needs to be placed in the same open spot is really high, with this not very well distributed key naming strategy).
A possible fix might be to md5 the whole combined string, not just the $key variable: md5($this->storageIdentifier . $key)

The same might be true for Flow 9.0:

return $storageIdentifier->value . md5($key);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions