psf / requests

A simple, yet elegant, HTTP library.
https://requests.readthedocs.io/en/latest/
Apache License 2.0
52.19k stars 9.33k forks source link

Any ipv6 request spuriously stays stuck for a long time, sometimes never progressing #6788

Closed sanjacob closed 3 months ago

sanjacob commented 3 months ago

I have an issue with my OS, that I am not sure how to diagnose, but it seems to affect requests too:

requests [required: >=2.20, installed: 2.32.3]
│   ├── certifi [required: >=2017.4.17, installed: 2024.7.4]
│   ├── charset-normalizer [required: >=2,<4, installed: 3.3.2]
│   ├── idna [required: >=2.5,<4, installed: 3.7]
│   └── urllib3 [required: >=1.21.1,<3, installed: 2.2.2]

Expected behaviour: requests hits timeout error Actual behaviour: Stuck for a long time (10-20 minutes+)

>>> requests.get("https://google.com", timeout=2000) # Using IPv6
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/.../.local/share/virtualenvs/.../lib/python3.10/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/home/.../.local/share/virtualenvs/.../lib/python3.10/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/.../.local/share/virtualenvs/.../lib/python3.10/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/.../.local/share/virtualenvs/.../lib/python3.10/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/home/.../.local/share/virtualenvs/.../lib/python3.10/site-packages/requests/adapters.py", line 667, in send
    resp = conn.urlopen(
  File "/home/.../.local/share/virtualenvs/.../lib/python3.10/site-packages/urllib3/connectionpool.py", line 789, in urlopen
    response = self._make_request(
  File "/home/.../.local/share/virtualenvs/.../lib/python3.10/site-packages/urllib3/connectionpool.py", line 466, in _make_request
    self._validate_conn(conn)
  File "/home/.../.local/share/virtualenvs/.../lib/python3.10/site-packages/urllib3/connectionpool.py", line 1095, in _validate_conn
    conn.connect()
  File "/home/.../.local/share/virtualenvs/.../lib/python3.10/site-packages/urllib3/connection.py", line 615, in connect
    self.sock = sock = self._new_conn()
  File "/home/.../.local/share/virtualenvs/.../lib/python3.10/site-packages/urllib3/connection.py", line 196, in _new_conn
    sock = connection.create_connection(
  File "/home/.../.local/share/virtualenvs/.../lib/python3.10/site-packages/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
KeyboardInterrupt
>>> requests.packages.urllib3.util.connection.HAS_IPV6 = False # manually disable ipv6
>>> requests.get("https://google.com", timeout=2000) # no problem with this
<Response [200]>
>>> requests.packages.urllib3.util.connection.HAS_IPV6 = True # tried request again and stuck for a long time

Unfortunately this also affects git push and git pull, so I know for a fact this is not a requests bug. But I do expect timeout to work in this rare(?) circumstance. Whatever the case, if you happen to know why my ipv6 connections seem to either take forever or never happen, please let me know.

github-actions[bot] commented 3 months ago

As described in the template, we won't be able to answer questions on this issue tracker. Please use Stack Overflow