Skip to content

Commit

Permalink
Restore UnprocessedRequestException
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Aug 23, 2023
1 parent d23811a commit 074e157
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
27 changes: 15 additions & 12 deletions src/Connection/DefaultConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ public function create(Request $request, Cancellation $cancellation): Connection
$cancellation->throwIfRequested();

// Otherwise we ran into a timeout of our TimeoutCancellation
throw new UnprocessedRequestException(new SocketException(\sprintf(
"Connection to '%s' timed out, took longer than " . $request->getTcpConnectTimeout() . ' s',
$authority
)));
throw new UnprocessedRequestException(
new TimeoutException(\sprintf("Connection to '%s' timed out, took longer than " . $request->getTcpConnectTimeout() . ' s', $authority))
);
}

if ($isHttps) {
Expand All @@ -125,7 +124,9 @@ public function create(Request $request, Cancellation $cancellation): Connection
if ($tlsState !== Socket\TlsState::Disabled) {
$socket->close();

throw new UnprocessedRequestException(new SocketException('Failed to setup TLS connection, connection was in an unexpected TLS state (' . $tlsState->name . ')'));
throw new UnprocessedRequestException(
new SocketException('Failed to setup TLS connection, connection was in an unexpected TLS state (' . $tlsState->name . ')')
);
}

$socket->setupTls(new CompositeCancellation(
Expand Down Expand Up @@ -158,11 +159,13 @@ public function create(Request $request, Cancellation $cancellation): Connection
if ($tlsInfo === null) {
$socket->close();

throw new UnprocessedRequestException(new SocketException(\sprintf(
"Socket closed after TLS handshake with '%s' @ '%s'",
$authority,
$socket->getRemoteAddress()->toString()
)));
throw new UnprocessedRequestException(
new SocketException(\sprintf(
"Socket closed after TLS handshake with '%s' @ '%s'",
$authority,
$socket->getRemoteAddress()->toString()
))
);
}

events()->tlsHandshakeEnd($request, $tlsInfo);
Expand Down Expand Up @@ -190,12 +193,12 @@ public function create(Request $request, Cancellation $cancellation): Connection
if (!\array_intersect($request->getProtocolVersions(), ['1.0', '1.1'])) {
$socket->close();

throw new UnprocessedRequestException(new SocketException(\sprintf(
throw new InvalidRequestException($request, \sprintf(
"None of the requested protocol versions (%s) are supported by '%s' @ '%s'",
\implode(', ', $protocolVersions),
$authority,
$socket->getRemoteAddress()->toString()
)));
));
}

$http1Connection = new Http1Connection($socket);
Expand Down
28 changes: 17 additions & 11 deletions src/Connection/Internal/Http2ConnectionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ public function initialize(Cancellation $cancellation): void
$this->initializeStarted = true;

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

$this->settings = new DeferredFuture;
Expand All @@ -145,9 +147,9 @@ public function initialize(Cancellation $cancellation): void
try {
$future->await($cancellation);
} catch (CancelledException $exception) {
$exception = new UnprocessedRequestException(new SocketException('Connecting cancelled', 0, $exception));
$exception = new SocketException('Connecting cancelled', 0, $exception);
$this->shutdown($exception);
throw $exception;
throw new UnprocessedRequestException($exception);
}
}

Expand Down Expand Up @@ -906,10 +908,12 @@ public function request(Request $request, Cancellation $cancellation, Stream $st
}

if ($this->hasTimeout && !$this->ping()->await()) {
throw new UnprocessedRequestException(new SocketException(\sprintf(
"Socket to '%s' missed responding to PINGs",
$this->socket->getRemoteAddress()->toString()
)));
throw new UnprocessedRequestException(
new SocketException(\sprintf(
"Socket to '%s' missed responding to PINGs",
$this->socket->getRemoteAddress()->toString()
))
);
}

RequestNormalizer::normalizeRequest($request);
Expand All @@ -928,10 +932,12 @@ public function request(Request $request, Cancellation $cancellation, Stream $st
$request->setProtocolVersions(['2']);

if ($this->socket->isClosed()) {
throw new UnprocessedRequestException(new SocketException(\sprintf(
"Socket to '%s' closed before the request could be sent",
$this->socket->getRemoteAddress()->toString()
)));
throw new UnprocessedRequestException(
new SocketException(\sprintf(
"Socket to '%s' closed before the request could be sent",
$this->socket->getRemoteAddress()->toString()
))
);
}

$body = $request->getBody()->getContent();
Expand Down
2 changes: 1 addition & 1 deletion test/ClientHttpBinIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ public function testNoMemoryLeak(): void
$initialIdentifierCount ??= \count(EventLoop::getIdentifiers());
$identifierCount = \count(EventLoop::getIdentifiers());

self::assertLessThan(1, $identifierCount - $initialIdentifierCount);
self::assertLessThanOrEqual(1, $identifierCount - $initialIdentifierCount);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/TimeoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public function testTimeoutDuringTlsEnableCatchable(): void
$this->client->request($request);

self::fail('No exception thrown');
} catch (TimeoutException $e) {
self::assertStringStartsWith('TLS handshake with \'127.0.0.1:', $e->getMessage());
} catch (UnprocessedRequestException $e) {
self::assertStringStartsWith('TLS handshake with \'127.0.0.1:', $e->getPrevious()->getMessage());
} finally {
$server->close();
}
Expand Down

0 comments on commit 074e157

Please sign in to comment.