Skip to content

Commit 796953d

Browse files
authored
fix: dead loop (#22)
* fix: dead loop According to the document on wiki.swoole.com, the correct way to check disconnection is emtpy($buffer), instead of $buffer===false. In our production environment, we periodically encounter infinite recv loops caused by the empty buffer. After the proposed change was made, the occasional dead loop went away. * Update SwooleSocket.php
1 parent 65cd680 commit 796953d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Socket/SwooleSocket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function recv(int $length, ?float $timeout = null): string
128128
$leftTime = $timeout;
129129
while ($this->socket && !isset($this->receivedBuffer[$length - 1]) && (-1 == $timeout || $leftTime > 0)) {
130130
$buffer = $this->socket->recv($timeout);
131-
if (false === $buffer) {
131+
if ($buffer === '' || $buffer === false) {
132132
throw new SocketException(sprintf('Could not recv data from stream, %s [%d]', $this->socket->errMsg, $this->socket->errCode));
133133
}
134134
$this->receivedBuffer .= $buffer;

0 commit comments

Comments
 (0)