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

Appearance settings

[DoctrineBridge] fix messenger bus dispatch inside an active transaction #57816

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

Merged

Conversation

IndraGunawan
Copy link
Contributor

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #...
License MIT

it was working fine with the below config and command.

# config/packages/messenger.yaml
framework:
    messenger:
        buses:
            sync_bus:
                middleware:
                    - validation
                    - doctrine_ping_connection
                    - doctrine_close_connection
                    - doctrine_open_transaction_logger
                    - doctrine_transaction
        routing:
            App\Message\SyncJob: sync
<?php
// src/Command/TestComand.php

namespace App\Command;

use App\Message\SyncJob;
use Doctrine\ORM\EntityManagerInterface;
// use ...

#[AsCommand(
    name: 'app:test',
    description: 'Add a short description for your command',
)]
class TestCommand extends Command
{
    public function __construct(
        private readonly EntityManagerInterface $em,
        private readonly MessageBusInterface $bus,
    )
    {
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);

        $this->bus->dispatch(new SyncJob('someone'));

        $io->success('You have a new command! Now make it your own! Pass --help to see your options.');

        return Command::SUCCESS;
    }
}

An issue occurs if I dispatch the message inside a transaction

$this->em->wrapInTransaction(function ($em) {
        // another process here
        $this->bus->dispatch(new SyncJob('someone'));
});

an error comes up

ERROR     [app] A handler opened a transaction but did not close it.

This PR aims to fix this issue without changing the existing behaviour

@carsonbot carsonbot added this to the 5.4 milestone Jul 24, 2024
@carsonbot carsonbot changed the title fix messenger bus dispatch inside an active transaction [DoctrineBridge] fix messenger bus dispatch inside an active transaction Jul 24, 2024
@nicolas-grekas nicolas-grekas force-pushed the fix-messenger-dispatch-transaction branch from 4e9be68 to f164370 Compare July 26, 2024 12:05
@nicolas-grekas
Copy link
Member

Thank you @IndraGunawan.

@nicolas-grekas nicolas-grekas merged commit a123a45 into symfony:5.4 Jul 26, 2024
10 of 12 checks passed
@IndraGunawan IndraGunawan deleted the fix-messenger-dispatch-transaction branch July 26, 2024 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.