Skip to content

ConnectionTerminated error_code:ErrorCodes.NO_ERROR #45

Closed

Description

@victoraugustolls

With httpx using httpcore interface, started receiving the following error:

<ConnectionTerminated error_code:ErrorCodes.NO_ERROR, last_stream_id:1999, additional_data:None>

Don't know h2 specifics to say, but could NO_ERROR be used for some indication like graceful connection closing rather than raising an error?

Activity

  1. lovelydinosaur commented on May 13, 2020

    @lovelydinosaur
    Member

    Do you know what the traceback is on this? Really we need to be catching that case in the HTTP/2 connection class and mapping it to a NewConnectionRequired exception. (The server is indicating that it has served the maximum number of streams that it'll allow on a connection, and that the client should reopen a new connection.)

  2. victoraugustolls commented on May 13, 2020

    @victoraugustolls
    ContributorAuthor

    I had in the past, will try to get a new one.

  3. lovelydinosaur commented on May 14, 2020

    @lovelydinosaur
    Member

    Looks like we deal with this correctly now, so I'm going to close it off, pending re-occurrence.

  4. victoraugustolls commented on Jul 16, 2020

    @victoraugustolls
    ContributorAuthor

    Hi @tomchristie , so... it happened again (tagging @yeraydiazdiaz and @florimondmanca also)!

    Here is the traceback:

    2020-07-16T15:28:11.813909653Z     response = await self.send(
    2020-07-16T15:28:11.813913353Z   File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1168, in send
    2020-07-16T15:28:11.813917153Z     response = await self.send_handling_redirects(
    2020-07-16T15:28:11.813920953Z   File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1195, in send_handling_redirects
    2020-07-16T15:28:11.813924853Z     response = await self.send_handling_auth(
    2020-07-16T15:28:11.813929653Z   File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1232, in send_handling_auth
    2020-07-16T15:28:11.813933653Z     response = await self.send_single_request(request, timeout)
    2020-07-16T15:28:11.813937453Z   File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1264, in send_single_request
    2020-07-16T15:28:11.813941353Z     ) = await transport.request(
    2020-07-16T15:28:11.813944953Z   File "/usr/local/lib/python3.8/site-packages/httpcore/_async/connection_pool.py", line 152, in request
    2020-07-16T15:28:11.813948953Z     response = await connection.request(
    2020-07-16T15:28:11.813952653Z   File "/usr/local/lib/python3.8/site-packages/httpcore/_async/connection.py", line 78, in request
    2020-07-16T15:28:11.813956554Z     return await self.connection.request(method, url, headers, stream, timeout)
    2020-07-16T15:28:11.813960654Z   File "/usr/local/lib/python3.8/site-packages/httpcore/_async/http2.py", line 118, in request
    2020-07-16T15:28:11.813964554Z     return await h2_stream.request(method, url, headers, stream, timeout)
    2020-07-16T15:28:11.813970554Z   File "/usr/local/lib/python3.8/site-packages/httpcore/_async/http2.py", line 292, in request
    2020-07-16T15:28:11.813974454Z     status_code, headers = await self.receive_response(timeout)
    2020-07-16T15:28:11.813978154Z   File "/usr/local/lib/python3.8/site-packages/httpcore/_async/http2.py", line 344, in receive_response
    2020-07-16T15:28:11.813982154Z     event = await self.connection.wait_for_event(self.stream_id, timeout)
    2020-07-16T15:28:11.813986054Z   File "/usr/local/lib/python3.8/site-packages/httpcore/_async/http2.py", line 197, in wait_for_event
    2020-07-16T15:28:11.813989954Z     await self.receive_events(timeout)
    2020-07-16T15:28:11.813993654Z   File "/usr/local/lib/python3.8/site-packages/httpcore/_async/http2.py", line 211, in receive_events
    2020-07-16T15:28:11.813997454Z     raise ProtocolError(event)
    2020-07-16T15:28:11.814001354Z httpcore._exceptions.ProtocolError: <ConnectionTerminated error_code:ErrorCodes.NO_ERROR, last_stream_id:1999, additional_data:None>```
    
  5. nathalie21005 commented on Jan 19, 2022

    @nathalie21005

    Hi @victoraugustolls,

    How did you solve this issue, I am facing the same problem.
    Thank you

  6. victoraugustolls commented on Jan 19, 2022

    @victoraugustolls
    ContributorAuthor

    Hey @nathalie21005 ! I don't have this issue on recent httpcore versions! Also, my assumption is that it was a host problem, not a client one!

  7. nathalie21005 commented on Jan 19, 2022

    @nathalie21005

    hey @victoraugustolls , thank you for replying. Can I know which version are you using for httpcore? thanks

  8. victoraugustolls commented on Jan 19, 2022

    @victoraugustolls
    ContributorAuthor

    I'm using it through httpx version v0.21.3

  9. twisteroidambassador commented on Mar 7, 2022

    @twisteroidambassador

    I think I have run into the same issue. After issuing many requests on an http2 connection using httpx, all subsequent requests fail immediately with httpx.RemoteProtocolError: <ConnectionTerminated error_code:ErrorCodes.NO_ERROR, last_stream_id:19999, additional_data:None>.

    Package versions:
    h2-4.1.0
    httpcore-0.14.7
    httpx-0.22.0

    Full traceback:

    Traceback (most recent call last):
      File "~\venv\lib\site-packages\h2\connection.py", line 224, in process_input
        func, target_state = self._transitions[(self.state, input_)]
    KeyError: (<ConnectionState.CLOSED: 3>, <ConnectionInputs.SEND_HEADERS: 0>)
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "~\venv\lib\site-packages\httpcore\_async\http2.py", line 105, in handle_async_request
        await self._send_request_headers(request=request, stream_id=stream_id)
      File "~\venv\lib\site-packages\httpcore\_async\http2.py", line 202, in _send_request_headers
        self._h2_state.send_headers(stream_id, headers, end_stream=end_stream)
      File "~\venv\lib\site-packages\h2\connection.py", line 766, in send_headers
        self.state_machine.process_input(ConnectionInputs.SEND_HEADERS)
      File "~\venv\lib\site-packages\h2\connection.py", line 228, in process_input
        raise ProtocolError(
    h2.exceptions.ProtocolError: Invalid input ConnectionInputs.SEND_HEADERS in state ConnectionState.CLOSED
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "~\venv\lib\site-packages\httpx\_transports\default.py", line 60, in map_httpcore_exceptions
        yield
      File "~\venv\lib\site-packages\httpx\_transports\default.py", line 353, in handle_async_request
        resp = await self._pool.handle_async_request(req)
      File "~\venv\lib\site-packages\httpcore\_async\connection_pool.py", line 253, in handle_async_request
        raise exc
      File "~\venv\lib\site-packages\httpcore\_async\connection_pool.py", line 237, in handle_async_request
        response = await connection.handle_async_request(request)
      File "~\venv\lib\site-packages\httpcore\_async\connection.py", line 90, in handle_async_request
        return await self._connection.handle_async_request(request)
      File "~\venv\lib\site-packages\httpcore\_async\http2.py", line 138, in handle_async_request
        raise RemoteProtocolError(self._connection_error_event)
    httpcore.RemoteProtocolError: <ConnectionTerminated error_code:ErrorCodes.NO_ERROR, last_stream_id:19999, additional_data:None>
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "~\decryptor.py", line 138, in do_decrypt_work
        resp = await client.get(test_v3_url)
      File "~\venv\lib\site-packages\httpx\_client.py", line 1729, in get
        return await self.request(
      File "~\venv\lib\site-packages\httpx\_client.py", line 1506, in request
        return await self.send(request, auth=auth, follow_redirects=follow_redirects)
      File "~\venv\lib\site-packages\httpx\_client.py", line 1593, in send
        response = await self._send_handling_auth(
      File "~\venv\lib\site-packages\httpx\_client.py", line 1621, in _send_handling_auth
        response = await self._send_handling_redirects(
      File "~\venv\lib\site-packages\httpx\_client.py", line 1658, in _send_handling_redirects
        response = await self._send_single_request(request)
      File "~\venv\lib\site-packages\httpx\_client.py", line 1695, in _send_single_request
        response = await transport.handle_async_request(request)
      File "~\venv\lib\site-packages\httpx\_transports\default.py", line 352, in handle_async_request
        with map_httpcore_exceptions():
      File "AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 153, in __exit__
        self.gen.throw(typ, value, traceback)
      File "~\venv\lib\site-packages\httpx\_transports\default.py", line 77, in map_httpcore_exceptions
        raise mapped_exc(message) from exc
    httpx.RemoteProtocolError: <ConnectionTerminated error_code:ErrorCodes.NO_ERROR, last_stream_id:19999, additional_data:None>
    
  10. tyteen4a03 commented on Mar 13, 2022

    @tyteen4a03

    Hi, also running into this issue.

  11. twisteroidambassador commented on Mar 15, 2022

    @twisteroidambassador

    I have created a discussion topic for this problem over at httpx's repository: encode/httpx#2112

    Perhaps we can get more attention over there.

  12. theChampionOne commented on Oct 7, 2024

    @theChampionOne

    same problem

  13. crackwitz commented on Sep 29, 2025

    @crackwitz

    the "user"-side solution is to wait with the requests until the connection is reestablished. that takes some user-side logic. I wish the library did that on its own in some way.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions