-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
get request hangs "in readinto return self._sock.recv_into(b)" without raising exception #3353
Comments
Thanks for this report! What worries me is that we're getting stuck even with a timeout. The timeout should prevent any socket call lasting longer than that number of seconds. This suggests two possibilities to me that aren't bugs, as well as the possibility of a bug (though it's unlikely). Firstly, can you use a print statement to confirm your timeout value at the call site? Secondly, it's possible that data is slowly being fed to the socket so that each individual socket call takes less than 10s. Can you try waiting to see if this problem resolves itself? Thirdly is the risk of bugs. For that I ideally need a reproducible script I can run in my own environment. Do you think you can produce one? |
Thanks for the quick answer! I can confirm via PyCharm Debugger and print statements that the timeout is 10 seconds for every call. It could be that data is slowly being fed, but it hanged for more than 8 hours the last time and This happened already for several datasets we're collecting. I will try to write something, but to make it reproducible I'd have to narrow down a smaller batch of urls causing it. This could take a while. |
Yeah, that's fine, there's no rush, but I'm unlikely to be able to discover this without a good repro scenario: it's likely that this is a weird interaction around sockets, forking, and the standard library. |
Ok, I think I found the url. But it's no problem with requests then. Rather a misconfigured webserver ... >>> r = requests.head('http://bluepoint-radio.de:9080/')
>>> r.headers
{'Content-Type': 'text/html'} 😡 Thanks for your help though. |
Yes, reproduces the error: >>> r = requests.get('http://bluepoint-radio.de:9080/', timeout=5)
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/miniconda3/envs/TQ/lib/python3.5/site-packages/requests/api.py", line 67, in get
:rtype: requests.Response
File "/home/ubuntu/miniconda3/envs/TQ/lib/python3.5/site-packages/requests/api.py", line 53, in request
# By using the 'with' statement we are sure the session is closed, thus we
File "/home/ubuntu/miniconda3/envs/TQ/lib/python3.5/site-packages/requests/sessions.py", line 468, in request
File "/home/ubuntu/miniconda3/envs/TQ/lib/python3.5/site-packages/requests/sessions.py", line 608, in send
# Shuffle things around if there's history.
File "/home/ubuntu/miniconda3/envs/TQ/lib/python3.5/site-packages/requests/models.py", line 737, in content
File "/home/ubuntu/miniconda3/envs/TQ/lib/python3.5/site-packages/requests/models.py", line 660, in generate
def generate():
File "/home/ubuntu/miniconda3/envs/TQ/lib/python3.5/site-packages/requests/packages/urllib3/response.py", line 344, in stream
:param decode_content:
File "/home/ubuntu/miniconda3/envs/TQ/lib/python3.5/site-packages/requests/packages/urllib3/response.py", line 301, in read
data = None
File "/home/ubuntu/miniconda3/envs/TQ/lib/python3.5/http/client.py", line 433, in read
n = self.readinto(b)
File "/home/ubuntu/miniconda3/envs/TQ/lib/python3.5/http/client.py", line 473, in readinto
n = self.fp.readinto(b)
File "/home/ubuntu/miniconda3/envs/TQ/lib/python3.5/socket.py", line 575, in readinto
return self._sock.recv_into(b)
KeyboardInterrupt
>>> |
Just for reference if somebody is looking this up: Use body content workflow instead of head requests to make content retrieval conditional. Headers from head requests seem to be unreliable. |
I have a very similar problem (if not the same): an application is randomly hanging (every ~10 to 20 days, roughly) and I connected
it just hangs here, apparently (I have no experience with @FlxVctr : thanks for the tip but I do not use head requests (nor body content workflow) |
That hang point seems to be in the standard library. Do you have a full Python traceback? |
@Lukasa : no, my program hung (without any traceback) and I was wondering what could have caused the hanging. I just did a |
gdb should be capable of printing a Python traceback. |
Ah, I still have what I tried on the terminal. Yes, there is indeed a traceback:
|
@wsw70 I should note that requests is not in that stack. 😉 |
Yes, I googled the question and saw references to Did I mention that requests is awesome? (and I really mean it, it is an opportunity to voice this out since the core dev is listening :) ) |
Yup. =P So that hang seems to be related to a TCP connection falling over. You'll have to take that up with the bottle devs. =D And I'm glad you like Requests! |
Having the same issue here. with timeout without it doesn't make any difference. It is hanging in the python3 "/home/devilfromir/code/src/utilities/deckdl/ddtokenizer.py" During handling of the above exception, another exception occurred: Traceback (most recent call last): This happens when i tunnel through tor using privoxy as http proxy |
遇到了同样的问题,进程在return self._sock.recv_into(b)这里卡住了 |
I had the same problem in windows,hangs in |
I'm having a similar issue. I tried to trace the problem by including the This is how I managed to get the traceback:
The issue seems related to the fact that I was issuing an http request to the same resource from whom I was called, in the same thread and before issuing a response to the caller. The following is the traceback of the hang --------Thread 139917216446208 "Thread-12" hangs ---------- |
I am also facing similar issue, using Python3.7 Code: r = sr.Recognizer() Error:- |
I'm having the same issue and it turns out that it is the socket getting disconnected. It works fine once the TCP keep alive options are set explicitly:
Requests version: Useful links: |
Hi,
I'm pretty desperately trying to nail down the reason that an url unshortener script is freezing from time to time.
I'm using requests with several head and get-requests, such as
where self.timeout are 10 seconds and the headers just include a user-agent.
The request is called by a worker in a multiprocessing Pool with 10 workers that get's constantly feeded via Pool.imap() with a list of urls.
When keyboard interrupting I get from some of the workers the following Traceback:
If the function would raise an exception, I've made sure that it would be catched within the function so that it would not block the pool. But as it seems,
readinto
is just hanging here (for hours). I don't know whether this is related to #3066, as I am not familiar enough with the protocols or requests itself, so please excuse a duplicate if this should be one or if the error is my bad.The freeze happened several times with the same batch of urls now.
I tried to find the exact url causing this freeze but did not succeed as the batch contains several thousand, though I've already excluded everything that exceeds a certain content length or does not have text as content type via a head request before the get.
I am running requests 2.10.0 with Python 3.5.1 in a miniconda environment installed via pip on an Ubuntu 14.04.
However, great library, hope this helps to make it better.
Cheers!
UPDATE:
Here the relevant code for the traceback (line 162 in unshorten.py):
The text was updated successfully, but these errors were encountered: