-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
error: [Errno 11] Resource temporarily unavailable - gunicorn and flask #514
Comments
I can easily recreate it. |
How are you running gunicorn? |
I run it from a command line as "gunicorn package:app". I tested it on both osx and ubuntu and got the same error on both platforms. |
Do you have any sample app I can test? |
I was testing my entire app via the simple flask web server (app.run). I then switched over to gunicorn once I had the app working and found the problem (erro 11...). I stripped the app down to the simplest hello world and it still fails under gunicorn. I must be missing something very obvious? Here is the app below. import traceback app = Flask(name) @app.route("/") @app.teardown_request Fails everytime. gunicorn --version => gunicorn (version 0.17.2) |
Thanks for the example. This error is expected [1] and ignored in gunicorn. You will notice that the request is correctly handled and finish,ie. no failure. What happen is that on some fast and quite idle systems the accept is taken by more than one worker for the same client (which is expected). The first to answer will block the socket for this error. Maybe this error should be removed from the stack. I'm not sure about it right now. (cc @tilgovi @sirkonst ) [1] https://github.com/benoitc/gunicorn/blob/master/gunicorn/workers/sync.py#L50 |
Thanks for looking into this. As far as I can tell, the exception occurs on every request. Am I to ignore it? How will I determine when a real error exists? |
Seems like we could change the log level for this one.
|
@tilgovi this is a log that come from flask inspecting the stacktrace. we should either let it or clear the stacktrace and log it. Is this what you mean? |
I have only been running with a single worker. Is it strange that there is a race condition on the socket? On Apr 22, 2013, at 1:51 AM, Benoit Chesneau notifications@github.com wrote:
|
How many connections ? On Mon, Apr 22, 2013 at 4:19 PM, tom notifications@github.com wrote:
|
Connections being inbound TCP requests? 1 at a time. I am just doing single user testing. On Apr 22, 2013, at 7:20 AM, Benoit Chesneau notifications@github.com wrote:
|
I think I see. gunicorn always starts 1 extra worker? Even with a gunicorn -w 1 simp:app, I see two workers via a ps aux. Oh maybe I got that wrong, one is the process doing the select and the other is actually honoring the request? |
@thomaswhitcomb np I made an optimisation there to make sure the worker won't be launched simultaneously. so they don't listen at the same time. Anyway this the next major iteration will also improve the accept loop. |
I was getting these errors 5 to 100 times per day, sometimes lots of these emails during an hour, and sometimes just 2 or 3 and then nothing for hours. I upgraded my gunicorn to the latest version which contains 3ade8e8, 18.0, but it didn't change the frequency of the emails. Today I discovered that it's actually a failure, and the viewer sees 500. The frequency of the emails is NOT correlated with the load/traffic/io/cpu of the server. I applied this solution about 10 hours ago and it seems that it has solved the problem. I haven't received any error yet. I can't understand why increasing the
|
Got 7 errors again, after 23 hours from the previous sequence of "Resource temporarily unavailable" errors. |
@remohammadi are you sure this results in 500 errors to the client? It may be a different issue even. I don't think SOMAXCONN is the issue here. |
I don't remember what was my observation which made me conclude that the user is getting 500 :( I'm still getting the error emails, but the frequency is low and so I'm ignoring it. |
I'm getting this say same with error with gunicorn + flask. It's intermittent but seems to be happening alot over the last 24 hours. Any updates here? |
This looks like a race condition. I think you're getting real socket exceptions, but your web app isn't reading the message from socket.error before gunicorn calls accept() again on the socket. That exception you see is thrown every time gunicorn calls accept() on a socket that doesn't have a client request waiting but it is ignored. Each python socket object has one error object. One line pull request if somebody with problems wants to try it: #709 |
I don't know if it's related, but I'm also receiving the
After a lot of searching I switched from sync worker to gevent worker (found this solution here: http://serverfault.com/questions/427600/gunicorn-django-nginx-unix-socket-failed-11-resource-temporarily-unavail/606371#606371) and now everything works as expected. I also tried the |
Maybe the sync worker is not always closing requests properly when there are error responses? |
If it helps, I found that our code was logging an exception when it should have been logging an error. If I remember correctly, there is one global variable in python that holds the last stack trace. Since gunicorn polls the socket over and over and catches this Errno 11 exception every time, this is the stack trace you will see if you print a stack trace when an exception hasn't actually been raised. |
@tilgovi How would I debug this? There seem to be no errors in the response in my development environment where I don't use gunicorn and neither are there any errors using the gevent worker. |
I tried the |
@ohadpartuck what is the gevent solution? Anything reproducible? Also this ticket has been closed if you have an issue please open a new one eventually linked to that one. It's hard to track the other way. |
|
still. what is the gevent solution? How can we reproduce the issue? This ticket has been closed anyway and new discussion should happen on a new ticket. the issue may or may not be different... |
Hey guys, just wondering if this was still being addressed or not? I've been having a similar issue. Flask seems aware but reluctant to do anything: pallets/flask#984 |
I was able to reproduce this issue here (using the Increasing the |
Is there a new issue where this is being discussed? |
I'm seeing this same issue when running with the datadog ddtrace-py library (with gunicorn 19.7.1):
The request is successful (200) but it's still generating a stack trace. run command looks like this:
|
There is a strange bug on windows whereby this stack trace is seen, File "c:\users\administrator\qtest\hypercorn\hypercorn\asyncio\run.py", line 140, in run_single server = loop.run_until_complete(create_server) File "C:\Program Files\Python37\lib\asyncio\base_events.py", line 574, in run_until_complete return future.result() File "C:\Program Files\Python37\lib\asyncio\base_events.py", line 1387, in create_server server._start_serving() File "C:\Program Files\Python37\lib\asyncio\base_events.py", line 277, in _start_serving sock.listen(self._backlog) OSError: [WinError 10022] An invalid argument was supplied I think this is a race condition when two processes listen on the same socket at the same time. However I can only intermittently reproduce this bug. This fix follows Gunicorn's practice (although Gunicorn applies this to all platforms), as discussed in benoitc/gunicorn#514 and implemented in benoitc/gunicorn@3ade8e8.
Related to #416
I'm running flask, gunicorn and am getting the exception: [Errno 11] Resource temporarily unavailable exception in the @app.teardown_request
I'm running these versions: Flask==0.9 and gunicorn==0.17.2
Here is my stack trace:
Traceback (most recent call last):
File "/home/tom/venv/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 39, in run
client, addr = sock.accept()
File "/usr/lib/python2.7/socket.py", line 202, in accept
sock, addr = self._sock.accept()
The text was updated successfully, but these errors were encountered: