Close connection on error while read or write

This commit is contained in:
2021-09-18 22:46:03 +03:00
parent fcd1f256ff
commit c8cd41777f

View File

@@ -205,24 +205,32 @@ abstract class Connection
protected function read(): Promise protected function read(): Promise
{ {
return call(function () {
try { try {
return $this->stream->read(); return $this->stream->read();
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
$this->close(false); $this->close(false);
return new Failure($e); return new Failure($e);
} }
});
} }
protected function write(string $data): Promise protected function write(string $data): Promise
{ {
return call(function () use ($data) {
try { try {
return $this->stream->write($data); return yield $this->stream->write($data);
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
$this->close(false); $this->close(false);
return new Failure($e); return new Failure($e);
} }
});
} }
protected function handleError(Frame\Error $error): void protected function handleError(Frame\Error $error): void