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

Commit af6a777

Browse filesBrowse files
committed
bug #47831 [Messenger] Fix amqp socket lost (GurvanVgx)
This PR was merged into the 5.4 branch. Discussion ---------- [Messenger] Fix amqp socket lost | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #42825 | License | MIT | Doc PR | N/A I'm taking the work done from someone else and and adding the remarks mentionned because there is no activity on this PR PR: #47574 Network can fail in many ways, sometimes pretty subtle. To avoid error messages "Library error: a socket error occurred", we detect when heartbeat as expired, and disconnect the chanmel connection, and force a reconnect. Here a explanation to justify the condition : https://www.rabbitmq.com/heartbeats.html#:~:text=Heartbeat%20frames%20are%20sent%20about,TCP%20connection%20will%20be%20closed. Commits ------- bdeef74 [Messenger] Fix amqp socket lost
2 parents 6a96afd + bdeef74 commit af6a777
Copy full SHA for af6a777

File tree

Expand file treeCollapse file tree

1 file changed

+12
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-0
lines changed

‎src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ class Connection
102102
*/
103103
private $amqpDelayExchange;
104104

105+
/**
106+
* @var int
107+
*/
108+
private $lastActivityTime = 0;
109+
105110
public function __construct(array $connectionOptions, array $exchangeOptions, array $queuesOptions, AmqpFactory $amqpFactory = null)
106111
{
107112
if (!\extension_loaded('amqp')) {
@@ -347,6 +352,8 @@ private function publishOnExchange(\AMQPExchange $exchange, string $body, string
347352
$attributes['delivery_mode'] = $attributes['delivery_mode'] ?? 2;
348353
$attributes['timestamp'] = $attributes['timestamp'] ?? time();
349354

355+
$this->lastActivityTime = time();
356+
350357
$exchange->publish(
351358
$body,
352359
$routingKey,
@@ -510,6 +517,11 @@ static function (): bool {
510517
}
511518
);
512519
}
520+
521+
$this->lastActivityTime = time();
522+
} elseif (0 < ($this->connectionOptions['heartbeat'] ?? 0) && time() > $this->lastActivityTime + 2 * $this->connectionOptions['heartbeat']) {
523+
$disconnectMethod = 'true' === ($this->connectionOptions['persistent'] ?? 'false') ? 'pdisconnect' : 'disconnect';
524+
$this->amqpChannel->getConnection()->{$disconnectMethod}();
513525
}
514526

515527
return $this->amqpChannel;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.