Skip to content

Commit 7dfaac0

Browse files
authored
Fix: Recreate disconnected connections when being retrieved (#19)
1 parent 9e69fb1 commit 7dfaac0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/ConnectionManager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public function connection(string $name = null): MqttClientContract
6060
$name = $this->defaultConnection;
6161
}
6262

63+
// Remove the connection if it is in a disconnected state.
64+
// Doing this instead of simply reconnecting ensures the caller will get a fresh connection.
65+
if (array_key_exists($name, $this->connections) && !$this->connections[$name]->isConnected()) {
66+
unset($this->connections[$name]);
67+
}
68+
6369
if (!array_key_exists($name, $this->connections)) {
6470
$this->connections[$name] = $this->createConnection($name);
6571
}

0 commit comments

Comments
 (0)