1
0
mirror of https://github.com/danog/amp.git synced 2024-11-26 12:04:42 +01:00

Fix potential issues when operating on destroyed uv handles in shutdown sequence

This commit is contained in:
Bob Weinand 2017-05-16 18:17:12 +02:00
parent de783b8eb1
commit 6e52f3e211
3 changed files with 41 additions and 8 deletions

View File

@ -260,34 +260,34 @@ class UvDriver extends Driver {
}
$event = $this->events[$id];
$eventId = (int) $event;
if (!\uv_is_active($event)) {
return;
}
switch ($watcher->type) {
case Watcher::READABLE:
case Watcher::WRITABLE:
$flags = 0;
$eventId = (int) $event;
foreach ($this->watchers[$eventId] as $watcher) {
$flags |= $watcher->enabled ? $watcher->type : 0;
}
if ($flags) {
\uv_poll_start($event, $flags, $this->ioCallback);
} elseif (\uv_is_active($event)) {
} else {
\uv_poll_stop($event);
}
break;
case Watcher::DELAY:
case Watcher::REPEAT:
if (\uv_is_active($event)) {
\uv_timer_stop($event);
}
\uv_timer_stop($event);
break;
case Watcher::SIGNAL:
if (\uv_is_active($event)) {
\uv_signal_stop($event);
}
\uv_signal_stop($event);
break;
default:

View File

@ -16,6 +16,9 @@
<testsuite name="Main">
<directory>test</directory>
</testsuite>
<testsuite name="PHPT tests">
<directory suffix=".phpt">test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>

View File

@ -0,0 +1,30 @@
--TEST--
Test order of destruction not interfering with access to UV handles
--SKIPIF--
<?php
extension_loaded("uv") or die("SKIP: ext/uv required for this test");
?>
--FILE--
<?php
include __DIR__.'/../../vendor/autoload.php';
use Amp\Loop;
Loop::run(function() {
Loop::setState('test', new class {
private $handle;
function __construct() {
$this->handle = Loop::repeat(10, function() {});
}
function __destruct() {
Loop::cancel($this->handle);
print "ok";
}
});
Loop::delay(0, [Loop::class, "stop"]);
});
?>
--EXPECT--
ok