Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] Doctrine transport does nothing to prevent race conditions when using sqlsrv DBAL driver #39117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thsmrtone1 opened this issue Nov 19, 2020 · 1 comment

Comments

@thsmrtone1
Copy link

Symfony version(s) affected: symfony/messenger:^4.4

Description
When Doctrine DBAL is set up to use SQL Server, and multiple message consumers are listening on the same doctrine transport, a message can be handled by more than one consumer simultaneously. It appears as though the DBAL platform getWriteLockSQL() method that the Messenger connection uses does not have compatibility with SQLServerPlatform (simply returns an empty string).

How to reproduce

  • Doctrine DBAL with sqlsrv connection
  • Many message consumers on the same doctrine transport/bus (tested with 5)

Possible Solution
Unknown if this can be fixed nor if there is a workaround. May need some documentation to explain the limitations.

Additional context
Queries that are executed as captured in logs:

[2020-11-19 15:08:24] doctrine.DEBUG: "START TRANSACTION" [] []
[2020-11-19 15:08:24] doctrine.DEBUG: SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY   ["2020-11-19 14:08:24","2020-11-19 15:08:24","default"] []
[2020-11-19 15:08:24] doctrine.DEBUG: UPDATE messenger_messages SET delivered_at = ? WHERE id = ? ["2020-11-19 15:08:24","7649"] []
[2020-11-19 15:08:24] doctrine.DEBUG: "COMMIT" [] []

^^ Notice there is no explicit lock on the select statement

@derrabus
Copy link
Member

For SQL Server, we would need to call $platform->appendLockHint() on the FROM clause. We're using DBAL's query builder to assemble the SQL and I'd like to keep it that way. But the query builder does not seem to bother about locks. :-/

thsmrtone1 pushed a commit to thsmrtone1/symfony that referenced this issue Nov 24, 2020
Add logic for locking row for update when the doctrine dbal connection is sqlsrv. This is a quick and dirty solution, but it prevents the need to rewrite the logic due to doctrine dbal limitations.

See issue symfony#39117
derrabus pushed a commit to thsmrtone1/symfony that referenced this issue Nov 28, 2020
Add logic for locking row for update when the doctrine dbal connection is sqlsrv. This is a quick and dirty solution, but it prevents the need to rewrite the logic due to doctrine dbal limitations.

See issue symfony#39117
symfony-splitter pushed a commit to symfony/messenger that referenced this issue Nov 28, 2020
Add logic for locking row for update when the doctrine dbal connection is sqlsrv. This is a quick and dirty solution, but it prevents the need to rewrite the logic due to doctrine dbal limitations.

See issue symfony/symfony#39117
symfony-splitter pushed a commit to symfony/messenger that referenced this issue Sep 28, 2021
Add logic for locking row for update when the doctrine dbal connection is sqlsrv. This is a quick and dirty solution, but it prevents the need to rewrite the logic due to doctrine dbal limitations.

See issue symfony/symfony#39117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants