Skip to content

Deadlocks on fresh MariaDB with high concurrency #2463

@vbpbeck

Description

@vbpbeck

Shlink version

4.4.6

PHP version

8.4.5

How do you serve Shlink

Docker image

Database engine

MariaDB

Database version

10/11

Current behavior

When transactions deadlock and require a rollback, these exceptions occur and produce an HTTP 500:

Shlink.ERROR - PDOException: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction in /etc/shlink/vendor/doctrine/dbal/src/Driver/PDO/Statement.php:55
Next Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT DOCTRINE_2 does not exist in /etc/shlink/vendor/doctrine/dbal/src/Driver/PDO/Exception.php:24

Stack traces:

DEADLOCK.txt
SAVEPOINT.txt

Expected behavior

No HTTP 500.

Minimum steps to reproduce

Compose.yaml:

compose.yaml.txt

Run:

docker compose up -d db
docker compose logs -f db

Wait for db to settle, ctrl-c

docker compose up -d app
docker compose logs -f app

See if shlink is up, ctrl-c

docker compose run --build crasher

Output will be like:

(... build ...)
New configuration template added to /tmp/.siege       
Run siege -C to view the current settings in that file

{       "transactions":                         3384, 
        "availability":                        99.82, 
        "elapsed_time":                         4.91, 
        "data_transferred":                     1.14, 
        "response_time":                        0.02, 
        "transaction_rate":                   689.21, 
        "throughput":                           0.23, 
        "concurrency":                         15.87, 
        "successful_transactions":              3384, 
        "failed_transactions":                     6, 
        "longest_transaction":                  0.22, 
        "shortest_transaction":                 0.01  
}

It seems the bug is more pronounced when the database is a bit busy growing files. The crasher therefore truncates short_urls on every start. This is on a system with fast NVMe. I guess it will be far worse on slower storage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions