Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f1e7f9a

Browse files
committed
Merge branch 'fix-eventloop-read-end' of https://github.com/clue/react into clue-fix-eventloop-read-end
2 parents fb4e562 + b671f6e commit f1e7f9a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/React/EventLoop/StreamSelectLoop.php

+4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ protected function runStreamSelect()
137137
if (stream_select($read, $write, $except, 0, $this->getNextEventTimeInMicroSeconds()) > 0) {
138138
if ($read) {
139139
foreach ($read as $stream) {
140+
if (!isset($this->readListeners[(int) $stream])) {
141+
continue;
142+
}
143+
140144
$listener = $this->readListeners[(int) $stream];
141145
call_user_func($listener, $stream, $this);
142146
}

tests/React/Tests/EventLoop/AbstractLoopTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,27 @@ public function stopShouldStopRunningLoop()
167167
$this->assertRunFasterThan(0.005);
168168
}
169169

170+
public function testIgnoreRemovedCallback()
171+
{
172+
$stream1 = fopen('php://temp', 'r+');
173+
$stream2 = fopen('php://temp', 'r+');
174+
// two independant streams, both should be readable right away
175+
176+
$loop = $this->loop;
177+
$loop->addReadStream($stream1, function ($stream) use ($loop, $stream2) {
178+
// stream1 is readable, remove stream2 as well => this will invalidate its callback
179+
$loop->removeReadStream($stream);
180+
$loop->removeReadStream($stream2);
181+
});
182+
$loop->addReadStream($stream2, function ($stream) use ($loop, $stream1) {
183+
// this callback would have to be called as well, but the first stream already removed us
184+
$loop->removeReadStream($stream);
185+
$loop->removeReadStream($stream1);
186+
});
187+
188+
$loop->run();
189+
}
190+
170191
private function assertRunFasterThan($maxInterval)
171192
{
172193
$start = microtime(true);

0 commit comments

Comments
 (0)