Skip to content

Commit

Permalink
Fix loop hanging if process is killed during handshake on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Sep 19, 2017
1 parent ca8f78b commit 03e7905
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/Internal/Windows/Handle.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public function __construct() {
/** @var Deferred[] */
public $stdioDeferreds;

/** @var string */
public $childPidWatcher;

/** @var string */
public $connectTimeoutWatcher;

Expand Down
7 changes: 4 additions & 3 deletions lib/Internal/Windows/SocketConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ private function readDataFromPendingClient($socket, int $length, PendingSocketCl
$state->receivedDataBuffer = '';

Loop::cancel($state->readWatcher);
Loop::cancel($state->timeoutWatcher);

return $data;
}
Expand Down Expand Up @@ -195,7 +194,9 @@ public function onReadableHandshakeAck($watcher, $socket) {
$handle->sockets[$pendingClient->streamId] = $socket;

if (count($handle->sockets) === 3) {
$pendingClient->readWatcher = Loop::onReadable($handle->sockets[0], [$this, 'onReadableChildPid'], $handle);
Loop::cancel($pendingClient->timeoutWatcher);

$handle->childPidWatcher = Loop::onReadable($handle->sockets[0], [$this, 'onReadableChildPid'], $handle);
$handle->stdioDeferreds[0]->resolve(new ResourceOutputStream($handle->sockets[0]));
$handle->stdioDeferreds[1]->resolve(new ResourceInputStream($handle->sockets[1]));
$handle->stdioDeferreds[2]->resolve(new ResourceInputStream($handle->sockets[2]));
Expand All @@ -209,7 +210,7 @@ public function onReadableChildPid($watcher, $socket, Handle $handle) {
return;
}

Loop::cancel($watcher);
Loop::cancel($handle->childPidWatcher);
Loop::cancel($handle->connectTimeoutWatcher);

if (\strlen($data) !== 5) {
Expand Down

0 comments on commit 03e7905

Please sign in to comment.