Skip to content

Release HTTP/2 semaphore permit on NoAvailableStreamIDError#1061

Open
bysiber wants to merge 1 commit intoencode:masterfrom
bysiber:fix-h2-semaphore-leak-stream-id-error
Open

Release HTTP/2 semaphore permit on NoAvailableStreamIDError#1061
bysiber wants to merge 1 commit intoencode:masterfrom
bysiber:fix-h2-semaphore-leak-stream-id-error

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 20, 2026

In the HTTP/2 implementation, handle_async_request / handle_request acquires a _max_streams_semaphore permit before getting a stream ID. If get_next_available_stream_id() raises NoAvailableStreamIDError, the exception handler correctly sets _used_all_stream_ids and decrements the request count, but it doesn't release the semaphore permit that was just acquired:

await self._max_streams_semaphore.acquire()      # permit consumed

try:
    stream_id = self._h2_state.get_next_available_stream_id()
    self._events[stream_id] = []
except h2.exceptions.NoAvailableStreamIDError:
    self._used_all_stream_ids = True
    self._request_count -= 1
    raise ConnectionNotAvailable()                # permit not released

This permanently leaks one semaphore permit. While the practical impact is limited since _used_all_stream_ids = True prevents further requests on this connection, it's still incorrect resource cleanup.

This adds the missing release() call in both the async and sync implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments