Skip to content

Commit

Permalink
Merge b6ac178 into 82d1641
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Oct 8, 2019
2 parents 82d1641 + b6ac178 commit 3fdcaca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
16 changes: 11 additions & 5 deletions src/Connection/DefaultConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ private function createConnection(
$cancellation
);
} catch (Socket\ConnectException $e) {
throw new SocketException(\sprintf("Connection to '%s' failed", $authority), 0, $e);
throw new UnprocessedRequestException(
new SocketException(\sprintf("Connection to '%s' failed", $authority), 0, $e)
);
} catch (CancelledException $e) {
// In case of a user cancellation request, throw the expected exception
$cancellation->throwIfRequested();
Expand All @@ -201,14 +203,16 @@ private function createConnection(
yield $socket->setupTls($tlsCancellationToken);
} elseif ($tlsState !== EncryptableSocket::TLS_STATE_ENABLED) {
$socket->close();
throw new SocketException('Failed to setup TLS connection, connection was in an unexpected TLS state (' . $tlsState . ')');
throw new UnprocessedRequestException(
new SocketException('Failed to setup TLS connection, connection was in an unexpected TLS state (' . $tlsState . ')')
);
}
} catch (StreamException $exception) {
$socket->close();
throw new SocketException(\sprintf(
throw new UnprocessedRequestException(new SocketException(\sprintf(
"Connection to '%s' closed during TLS handshake",
$authority
), 0, $exception);
), 0, $exception));
} catch (CancelledException $e) {
$socket->close();

Expand All @@ -225,7 +229,9 @@ private function createConnection(

$tlsInfo = $socket->getTlsInfo();
if ($tlsInfo === null) {
throw new SocketException('Socket disconnected immediately after enabling TLS');
throw new UnprocessedRequestException(
new SocketException('Socket disconnected immediately after enabling TLS')
);
}

if ($tlsInfo->getApplicationLayerProtocol() === 'h2') {
Expand Down
15 changes: 10 additions & 5 deletions src/Connection/Http2Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ public function initialize(): Promise
$this->initialized = true;

if ($this->socket->isClosed()) {
return new Failure(new SocketException('The socket closed before the connection could be initialized'));
return new Failure(new UnprocessedRequestException(
new SocketException('The socket closed before the connection could be initialized')
));
}

$this->settingsDeferred = new Deferred;
Expand Down Expand Up @@ -312,7 +314,6 @@ private function request(Request $request, CancellationToken $token): Promise

if ($this->socket->isClosed()) {
throw new UnprocessedRequestException(
$request,
new SocketException(\sprintf(
"Socket to '%s' closed before the request could be sent",
$this->socket->getRemoteAddress()
Expand Down Expand Up @@ -918,7 +919,11 @@ private function parser(): \Generator
$error = \unpack("N", $buffer)[1];

if (isset($this->streams[$id])) {
$this->releaseStream($id, new SocketException("Server ended stream", $error));
$exception = new Http2StreamException("Stream closed by server", $id, $error);
if ($error === self::REFUSED_STREAM) {
$exception = new UnprocessedRequestException($exception);
}
$this->releaseStream($id, $exception);
}

$buffer = \substr($buffer, 4);
Expand Down Expand Up @@ -1457,8 +1462,8 @@ private function shutdown(?int $lastId = null, ?\Throwable $reason = null): Prom
$reason = $exception = $reason ?? new SocketException("Connection closed");
foreach ($this->streams as $id => $stream) {
$exception = $reason;
if ($id > $lastId && $stream->request !== null) {
$exception = new UnprocessedRequestException($stream->request, $reason);
if ($id > $lastId) {
$exception = new UnprocessedRequestException($reason);
}

$this->releaseStream($id, $exception);
Expand Down

0 comments on commit 3fdcaca

Please sign in to comment.