Skip to content
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

[Messenger][Doctrine] cleanup only the configured queue_name #54821

Open
smatyas opened this issue May 2, 2024 · 0 comments
Open

[Messenger][Doctrine] cleanup only the configured queue_name #54821

smatyas opened this issue May 2, 2024 · 0 comments

Comments

@smatyas
Copy link
Contributor

smatyas commented May 2, 2024

Symfony version(s) affected

4.4-7.1

Description

Using a master-master mysql replica, a couple of transports with different queue_name-s and separate consumers by transports, it can easily happen that the cleanup statements will result in replication error due to preventable race-conditions.

If we run distinct consumers against the replicated dbs, it should not happen, if the cleanup queries would filter for the queue name. Currently every consumer deletes old records even from unrelated queues.

I know that we could workaround this problem with separate tables, but I think it might be a nice and correct addition for the current implementation.

The current implementation does not filter for the 'queu_name', but it should:

-                 $this->driverConnection->delete($this->configuration['table_name'], ['delivered_at' => '9999-12-31 23:59:59']);
+                $this->driverConnection->delete($this->configuration['table_name'], ['delivered_at' => '9999-12-31 23:59:59', 'queue_name' => $this->configuration['queue_name']]);

How to reproduce

  1. create a master-master mysql replica
  2. create multiple transport using the same table
# messenger.yaml
# ...
        transports:
            job_a:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%?queue_name=job_a'
            job_b:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%?queue_name=job_b'
  1. consume job_a from db-server-a using multiple consumers
  2. consume job_b from db-server-b using multiple consumers

Possible Solution

Do the cleanup only for the configured queue_name.

In Symfony\Component\Messenger\Bridge\Doctrine\Transport::get

-                 $this->driverConnection->delete($this->configuration['table_name'], ['delivered_at' => '9999-12-31 23:59:59']);
+                $this->driverConnection->delete($this->configuration['table_name'], ['delivered_at' => '9999-12-31 23:59:59', 'queue_name' => $this->configuration['queue_name']]);

Additional Context

We experienced this issue with symfony 4.4, but I can see from the code that it still works the same way.

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

2 participants