lock icon indicating copy to clipboard operation
lock copied to clipboard

MySQLMutex doesn't work correctly together with Sentry

Open eddokloosterman opened this issue 3 years ago • 1 comments

After upgrading Symfony and Sentry ("sentry/sentry-symfony": "^4.3.0") I got the message that I needed to also upgrade doctrine/dbal ("doctrine/dbal": "^2.13.9",) , which then subsequently broke my use of MySQLMutex.

<b>Fatal error</b>:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 
passed to malkusch\lock\mutex\MySQLMutex::__construct() must be an instance of PDO, instance of 
Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingServerInfoAwareDriverConnection given, called in 
/var/www/html/src/ApiBundle/Controller/Invoicing/InvoiceController.php on line 533 in 
/var/www/html/vendor/malkusch/lock/classes/mutex/MySQLMutex.php:27

The MySQLMutex class only expects an instance of PDO to be provided, and in my case this is actually an instance of the Doctrine\DBAL\Connection interface with the updated Sentry package.

$em = $this->getContainer()->get('doctrine.orm.entity_manager');
$pdo = $em->getConnection()->getWrappedConnection();
$mutex = new MySQLMutex($pdo, 'Some lock');

A solution would be to adapt the package so that the MySQLMutex class accepts both an instance of PDO and Doctrine\DBAL\Connection.

Might make a PR for this in the coming week.

eddokloosterman avatar Oct 05 '22 13:10 eddokloosterman

I think you should just call \Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingServerInfoAwareDriverConnection::getNativeConnection or \Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingServerInfoAwareDriverConnection::getWrappedConnection again on the object until you get the PDO object. Can you give it a shot?

willemstuursma avatar Oct 10 '22 11:10 willemstuursma