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
{
try {
return $this->stream->read();
} catch (\Throwable $e) {
$this->close(false);
return call(function () {
try {
return $this->stream->read();
} catch (\Throwable $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
return new Failure($e);
}
$this->close(false);
return new Failure($e);
}
});
}
protected function write(string $data): Promise
{
try {
return $this->stream->write($data);
} catch (\Throwable $e) {
$this->close(false);
return call(function () use ($data) {
try {
return yield $this->stream->write($data);
} catch (\Throwable $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
return new Failure($e);
}
$this->close(false);
return new Failure($e);
}
});
}
protected function handleError(Frame\Error $error): void