Skip to content

Fix unsupported EventConfig and SEGFAULTs on shutdown for ext-event on Windows #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ matrix:
- export PATH="$(powershell -Command '("Process", "Machine" | % { [Environment]::GetEnvironmentVariable("PATH", $_) -Split ";" -Replace "\\$", "" } | Select -Unique | % { cygpath $_ }) -Join ":"')"
install:
- composer install
- name: "Windows PHP 7.2 with ext-event"
os: windows
language: shell # no built-in php support
before_install:
- curl -OL https://windows.php.net/downloads/pecl/releases/event/2.5.3/php_event-2.5.3-7.2-nts-vc15-x64.zip # latest version as of 2019-12-23
- choco install php --version=7.2.26 # latest version supported by ext-event as of 2019-12-23
- choco install composer
- export PATH="$(powershell -Command '("Process", "Machine" | % { [Environment]::GetEnvironmentVariable("PATH", $_) -Split ";" -Replace "\\$", "" } | Select -Unique | % { cygpath $_ }) -Join ":"')"
- php -r "\$z=new ZipArchive();\$z->open(glob('php_event*.zip')[0]);\$z->extractTo(dirname(php_ini_loaded_file()).'/ext','php_event.dll');"
- php -r "file_put_contents(php_ini_loaded_file(),'extension_dir=ext'.PHP_EOL,FILE_APPEND);"
- php -r "file_put_contents(php_ini_loaded_file(),'extension=sockets'.PHP_EOL,FILE_APPEND);" # ext-sockets needs to be loaded before ext-event
- php -r "file_put_contents(php_ini_loaded_file(),'extension=event'.PHP_EOL,FILE_APPEND);"
install:
- composer install
allow_failures:
- php: hhvm
- os: windows
Expand Down
21 changes: 18 additions & 3 deletions src/ExtEventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use BadMethodCallException;
use Event;
use EventBase;
use EventConfig as EventBaseConfig;
use React\EventLoop\Tick\FutureTickQueue;
use React\EventLoop\Timer\Timer;
use SplObjectStorage;
Expand Down Expand Up @@ -43,8 +42,13 @@ public function __construct()
throw new BadMethodCallException('Cannot create ExtEventLoop, ext-event extension missing');
}

$config = new EventBaseConfig();
$config->requireFeatures(EventBaseConfig::FEATURE_FDS);
// support arbitrary file descriptors and not just sockets
// Windows only has limited file descriptor support, so do not require this (will fail otherwise)
// @link http://www.wangafu.net/~nickm/libevent-book/Ref2_eventbase.html#_setting_up_a_complicated_event_base
$config = new \EventConfig();
if (\DIRECTORY_SEPARATOR !== '\\') {
$config->requireFeatures(\EventConfig::FEATURE_FDS);
}

$this->eventBase = new EventBase($config);
$this->futureTickQueue = new FutureTickQueue();
Expand All @@ -55,6 +59,17 @@ public function __construct()
$this->createStreamCallback();
}

public function __destruct()
{
// explicitly clear all references to Event objects to prevent SEGFAULTs on Windows
foreach ($this->timerEvents as $timer) {
$this->timerEvents->detach($timer);
}

$this->readEvents = array();
$this->writeEvents = array();
}

public function addReadStream($stream, $listener)
{
$key = (int) $stream;
Expand Down