Skip to content
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
15 changes: 13 additions & 2 deletions src/s2_sdk/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,26 @@ async def checkout(self, base_url: str) -> _Checkout:
except asyncio.TimeoutError:
pass # Proceed with h2 defaults

if conn._goaway_received:
await conn.close()
raise ConnectError(
f"Server sent GOAWAY on connection to {host}:{port} before "
"an HTTP/2 request stream could be reserved"
)

if conn._recv_dead:
await conn.close()
raise ConnectError(
f"Connection to {host}:{port} closed before HTTP/2 SETTINGS"
f"HTTP/2 receive loop for connection to {host}:{port} "
"terminated before a request stream could be reserved"
)

if conn._settings_received.is_set() and conn.max_concurrent_streams <= 0:
await conn.close()
raise ProtocolError("Connection has no available stream capacity")
raise ConnectError(
f"Server's initial HTTP/2 SETTINGS for {host}:{port} "
"advertised zero concurrent streams"
)

pc = await self._add_connection(base_url, conn)
state = pc._conn.reserve_stream()
Expand Down
5 changes: 3 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
_StreamState,
)
from s2_sdk._exceptions import (
ConnectError,
ConnectionClosedError,
ProtocolError,
ReadTimeoutError,
S2ClientError,
S2ServerError,
Expand All @@ -37,6 +37,7 @@ def _mock_connection(
conn.close = AsyncMock()
conn._streams = {}
conn._pending_streams = {}
conn._goaway_received = False
conn._recv_dead = False
conn._settings_received = asyncio.Event()
conn._settings_received.set()
Expand Down Expand Up @@ -176,7 +177,7 @@ async def test_new_connection_with_zero_stream_capacity_raises(pool: ConnectionP
conn = _mock_connection(max_concurrent_streams=0)
MockConn.return_value = conn

with pytest.raises(ProtocolError, match="no available stream capacity"):
with pytest.raises(ConnectError, match="zero concurrent streams"):
await pool.checkout("https://example.com")

conn.close.assert_awaited_once()
Expand Down
Loading