Skip to content

Commit fb8e0eb

Browse files
committed
[Stream] Fix infinite loop writing to closed stream
1 parent c212d55 commit fb8e0eb

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Buffer.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Evenement\EventEmitter;
66
use React\EventLoop\LoopInterface;
7-
use React\Stream\WritableStreamInterface;
87

98
/** @event full-drain */
109
class Buffer extends EventEmitter implements WritableStreamInterface
@@ -83,8 +82,8 @@ public function close()
8382

8483
public function handleWrite()
8584
{
86-
if (!is_resource($this->stream) || ('generic_socket' === $this->meta['stream_type'] && feof($this->stream))) {
87-
$this->emit('error', array(new \RuntimeException('Tried to write to closed or invalid stream.')));
85+
if (!is_resource($this->stream)) {
86+
$this->emit('error', array(new \RuntimeException('Tried to write to invalid stream.'), $this));
8887

8988
return;
9089
}
@@ -107,6 +106,12 @@ public function handleWrite()
107106
return;
108107
}
109108

109+
if (0 === $sent && feof($this->stream)) {
110+
$this->emit('error', array(new \RuntimeException('Tried to write to closed stream.'), $this));
111+
112+
return;
113+
}
114+
110115
$len = strlen($this->data);
111116
if ($len >= $this->softLimit && $len - $sent < $this->softLimit) {
112117
$this->emit('drain');

0 commit comments

Comments
 (0)