Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Database lock fails in transaction on PostgreSQL on second attempt #61125

Open
@Steveb-p

Description

@Steveb-p

Symfony version(s) affected

7.3

Description

Current implementation of Symfony Lock forPdoStore /DoctrineDbalStore will fail on PostgreSQL if:

  • Database connection has an open transaction
  • An attempt is made to acquire a lock on a key for a 2nd time

The error message will be:

current transaction is aborted, commands ignored until end of transaction block

and will appear on any SQL statement sent to the database after Store fails toINSERT (

$sql ="INSERT INTO$this->table ($this->idCol,$this->tokenCol,$this->expirationCol) VALUES (:id, :token,{$this->getCurrentTimestampStatement()} +$this->initialTtl)";
here).

Normally it would rarely happen and be limited to developer usage of the lock, but now since Symfony Messenger has deduplication feature - which combines Symfony Lock - there is a high likelihood that dispatching messages within a transaction can lead to an unrecoverable error (when deduplication mechanism should trigger a skip).

How to reproduce

Following test case can be used to trigger the error.

/**     * @requires extension pdo_pgsql     *     * @group integration     */publicfunctiontestTransactionWithPostgreSQL():void    {if (!$host =getenv('POSTGRES_HOST')) {$this->markTestSkipped('Missing POSTGRES_HOST env variable');        }$key =newKey(__METHOD__);$dsn ='pgsql:host='.$host.';user=postgres;password=password';$pdo =new \PDO($dsn);$pdo->beginTransaction();try {$store =newPdoStore($pdo);$store->save($key);$this->assertTrue($store->exists($key));$store->save($key);        }finally {$pdo =new \PDO($dsn);$pdo->exec('DROP TABLE IF EXISTS lock_keys');        }    }

Possible Solution

I'd be happy to provide a PR with a fix, but would need directions on how to approach this.

Additional Context

I was able to trigger the issue both in tests (since I am using DAMA Doctrine bundle for tests I have database transaction open almost immediately), and in a real application - when dispatching a message that needed deduplication (i.e. should be skipped).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp