Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294339

Core Symfony Mailer throws error on transport shutdown

$
0
0

Problem/Motivation

I'm trying to send emails using the Symfony Mailer component in core, with SMTP transport.

SMTP mails are sent out successfully. After sending, Symfony mailer tries to log the transport shutdown, which results in an error thrown:

Fatal error: Uncaught TypeError: Drupal\Core\Database\StatementWrapperIterator::__construct(): Argument #2 ($clientConnection) must be of type object, null given, called in /app/web/core/lib/Drupal/Core/Database/Connection.php on line 557 and defined in /app/web/core/lib/Drupal/Core/Database/StatementWrapperIterator.php on line 54 TypeError: Drupal\Core\Database\StatementWrapperIterator::__construct(): Argument #2 ($clientConnection) must be of type object, null given, called in /app/web/core/lib/Drupal/Core/Database/Connection.php on line 557 in /app/web/core/lib/Drupal/Core/Database/StatementWrapperIterator.php on line 54 Call Stack: 0.6247 15039456 1. Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->__destruct() /app/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php:0 0.6247 15039456 2. Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->stop() /app/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php:390 0.6247 15039776 3. Drupal\Core\Logger\LoggerChannel->debug($message = 'Email transport "Symfony\\Component\\Mailer\\Transport\\Smtp\\SmtpTransport" stopping', $context = ???) /app/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php:297 0.6247 15039776 4. Drupal\Core\Logger\LoggerChannel->log($level = 'debug', $message = 'Email transport "Symfony\\Component\\Mailer\\Transport\\Smtp\\SmtpTransport" stopping', $context = []) /app/vendor/psr/log/src/LoggerTrait.php:127 0.6247 15040432 5. Drupal\dblog\Logger\DbLog->log($level = 7, $message = 'Email transport "Symfony\\Component\\Mailer\\Transport\\Smtp\\SmtpTransport" stopping', $context = ['channel' => 'mail', 'link' => '', 'uid' => '1', 'request_uri' => 'http://igk-d10.dev.localhost/user/650', 'referer' => 'http://igk-d10.dev.localhost/user/650', 'ip' => '172.16.112.2', 'timestamp' => 1707476301]) /app/web/core/lib/Drupal/Core/Logger/LoggerChannel.php:127 0.6248 15042624 6. Drupal\mysql\Driver\Database\mysql\Insert->execute() /app/web/core/modules/dblog/src/Logger/DbLog.php:78 0.6248 15044328 7. Drupal\Core\Database\Connection->prepareStatement($query = 'INSERT INTO {watchdog} ("uid", "type", "message", "variables", "severity", "link", "location", "referer", "hostname", "timestamp") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9)', $options = [], $allow_row_count = ???) /app/web/core/modules/mysql/src/Driver/Database/mysql/Insert.php:42 0.6248 15044968 8. Drupal\Core\Database\StatementWrapperIterator->__construct($connection = class Drupal\mysql\Driver\Database\mysql\Connection { protected $target = 'default'; protected $key = 'default'; protected $logger = NULL; protected $transactionLayers = []; protected $driverClasses = []; protected $statementWrapperClass = 'Drupal\\Core\\Database\\StatementWrapperIterator'; protected $transactionalDDLSupport = FALSE; protected $connection = NULL; protected $connectionOptions = ['database' => 'drupal10', 'username' => 'drupal10', 'password' => 'drupal10', 'prefix' => '', 'host' => 'database', 'port' => '3306', 'namespace' => 'Drupal\\mysql\\Driver\\Database\\mysql', 'driver' => 'mysql', 'init_commands' => [...], 'autoload' =>

It seems Symfony Mailer tries to log the message 'Email transport "Symfony\\Component\\Mailer\\Transport\\Smtp\\SmtpTransport" stopping', but the logger does not find the database connection.
Other smtp transport messages get logged successfully:

Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" starting
...
Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" started
...
// After send, "Stopping" message can't be logged

Steps to reproduce

Add smtp config to settings.php:

$config['system.mail']['interface'] = [ 'default' => 'symfony_mailer' ];
$config['system.mail']['mailer_dsn'] = [
  'scheme' => 'smtp',
  'host' => 'my.smtp.host',
  'port' => 465,
  'user' => 'myuser',
  'password' => 'mypassword',
];

Trigger some action which will send an email (e.g., using drush).

Proposed resolution

The log messages emitted by symfony mailer transports are of no use anyway (see #11). Hence, do not inject any logger channel into the transport factories.

Remaining tasks

  • Update the PR
  • Review
  • Commit

User interface changes

None


Viewing all articles
Browse latest Browse all 294339

Trending Articles