Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: list.remove(x): x not in list #670

Closed
dimaqq opened this issue Apr 18, 2023 · 5 comments
Closed

ValueError: list.remove(x): x not in list #670

dimaqq opened this issue Apr 18, 2023 · 5 comments

Comments

@dimaqq
Copy link

dimaqq commented Apr 18, 2023

Apologies for a not-very-well-formed bug report.

I was only able to hit this under rather weird conditions (streaming responses, backpressure, connection pool full).

ERROR:hypercorn.error:Error in ASGI Framework
Traceback (most recent call last):
  File "/home/proxy/.cache/pypoetry/virtualenvs/proxy-9E6wT_fw-py3.10/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 227, in handle_async_request
    connection = await status.wait_for_connection(timeout=timeout)
  File "/home/proxy/.cache/pypoetry/virtualenvs/proxy-9E6wT_fw-py3.10/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 34, in wait_for_connection
    await self._connection_acquired.wait(timeout=timeout)
  File "/home/proxy/.cache/pypoetry/virtualenvs/proxy-9E6wT_fw-py3.10/lib/python3.10/site-packages/httpcore/_synchronization.py", line 38, in wait
    await self._event.wait()
  File "/home/proxy/.cache/pypoetry/virtualenvs/proxy-9E6wT_fw-py3.10/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 1842, in wait
    if await self._event.wait():
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 214, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/proxy/.cache/pypoetry/virtualenvs/proxy-9E6wT_fw-py3.10/lib/python3.10/site-packages/hypercorn/asyncio/task_group.py", line 23, in _handle
    await app(scope, receive, send, sync_spawn, call_soon)
  File "/home/proxy/.cache/pypoetry/virtualenvs/proxy-9E6wT_fw-py3.10/lib/python3.10/site-packages/hypercorn/app_wrappers.py", line 33, in __call__
    await self.app(scope, receive, send)
  File "/home/proxy/proxy/app.py", line 119, in app
    async with config.upstream_client.stream(
  File "/usr/local/lib/python3.10/contextlib.py", line 199, in __aenter__
    return await anext(self.gen)
  File "/home/proxy/.cache/pypoetry/virtualenvs/proxy-9E6wT_fw-py3.10/lib/python3.10/site-packages/httpx/_client.py", line 1570, in stream
    response = await self.send(
  File "/home/proxy/.cache/pypoetry/virtualenvs/proxy-9E6wT_fw-py3.10/lib/python3.10/site-packages/httpx/_client.py", line 1614, in send
    response = await self._send_handling_auth(
  File "/home/proxy/.cache/pypoetry/virtualenvs/proxy-9E6wT_fw-py3.10/lib/python3.10/site-packages/httpx/_client.py", line 1642, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/home/proxy/.cache/pypoetry/virtualenvs/proxy-9E6wT_fw-py3.10/lib/python3.10/site-packages/httpx/_client.py", line 1679, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/home/proxy/.cache/pypoetry/virtualenvs/proxy-9E6wT_fw-py3.10/lib/python3.10/site-packages/httpx/_client.py", line 1716, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/home/proxy/.cache/pypoetry/virtualenvs/proxy-9E6wT_fw-py3.10/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/home/proxy/.cache/pypoetry/virtualenvs/proxy-9E6wT_fw-py3.10/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 233, in handle_async_request
    self._requests.remove(status)
ValueError: list.remove(x): x not in list

At the very end, when httpcore fails here:

except BaseException as exc:
# If we timeout here, or if the task is cancelled, then make
# sure to remove the request from the queue before bubbling
# up the exception.
async with self._pool_lock:
self._requests.remove(status)
raise exc

@dimaqq
Copy link
Author

dimaqq commented Apr 18, 2023

Versions:

  • Python 3.10.5, Linux
  • httpcore 0.15.0 A minimal low-level HTTP client.
  • httpx 0.23.0 The next generation HTTP client.

@Tunglies
Copy link
Contributor

Tunglies commented May 7, 2023

Some example code would be useful.

@dimaqq
Copy link
Author

dimaqq commented May 9, 2023

I don't have an MRE, as this is relatively rare and happens in prod under unusual conditions.
Maybe I can copy-paste the user code that seems relevant.

@dimaqq
Copy link
Author

dimaqq commented May 9, 2023

    async with AsyncClient(
        proxies=...,  # using a SOCKS5 proxy from `httpx[socks]`
        limits=Limits(max_connections=...),
        timeout=...,
        cookies=...,
    ) as config.upstream_client:

# ...

        async with config.upstream_client.stream(method, str(url), headers=..., content=...) as resp:
            ...
            response = StreamingResponse(resp.aiter_bytes(), status_code=..., headers=...)
            ...
            await response(scope, receive, send)

tomchristie pushed a commit that referenced this issue May 17, 2023
* Fix ValueError: list.remove(x): x not in list (#670)

* Fix ValueError: list.remove(x): x not in list (#670)
@tomchristie
Copy link
Member

Closed via #680

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

No branches or pull requests

3 participants