Skip to content

Commit a6816e5

Browse files
committed
Remove listener only on sucessful attempt
1 parent 56cf65a commit a6816e5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/ProxyConnector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,10 @@ public function connect($uri)
188188

189189
$stream->write("CONNECT " . $host . ":" . $port . " HTTP/1.1\r\nHost: " . $host . ":" . $port . "\r\n" . $auth . "\r\n");
190190

191-
return $deferred->promise()->always(function () use ($stream, $fn) {
192-
// Stop buffering when connection has been established or rejected.
191+
return $deferred->promise()->then(function (ConnectionInterface $stream) use ($fn) {
192+
// Stop buffering when connection has been established.
193193
$stream->removeListener('data', $fn);
194+
return new Promise\FulfilledPromise($stream);
194195
});
195196
}, function (Exception $e) use ($proxyUri) {
196197
throw new RuntimeException('Unable to connect to proxy (ECONNREFUSED)', defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111, $e);

0 commit comments

Comments
 (0)