Skip to content

Commit b713b99

Browse files
Merge pull request #37 from utopia-php/amqp-loop
fix(amqp): properly close connection on errors and open clean, new connection
2 parents b8cd955 + ba90669 commit b713b99

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/Queue/Broker/AMQP.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,16 @@ private function withChannel(callable $callback): void
189189
return $channel;
190190
};
191191

192-
if ($this->channel == null) {
192+
if (!$this->channel) {
193193
$this->channel = $createChannel();
194194
}
195195

196196
try {
197197
$callback($this->channel);
198198
} catch (\Throwable $th) {
199-
// try to create a new connection once
200-
unset($this->channel);
199+
// createChannel() might throw, in that case set the channel to `null` first.
200+
$this->channel = null;
201+
// try creating a new connection once, if this still fails, throw the error
201202
$this->channel = $createChannel();
202203
$callback($this->channel);
203204
}

0 commit comments

Comments
 (0)