-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Problem with uvloop and static files #1093
Comments
Nice catch! |
Affects me as well (as mentioned in the issue referenced above). |
Hm. The general idea is to make sure that the headers are flushed, sent, and the original socket is closed. Then do I also think it's time to add sendfile implementation to asyncio. Will try to work on that. |
Closing original socket effectively prevents HTTP pilpelining, which is especially effective for file sending. |
Does anyone use this in production? |
Not yet, but I'm about to put an |
I mean you shouldn't ever serve static files with aiohttp in production -- you should use nginx (or another http server) for that. |
Not in my case, that was going to be used just for a manual test which was going to be run once (or twice) and then disabled. Your last point is not valid, since a number of applications do serve static files in production as the backend for CDNs. This means that they do provide the original files, although the "big hits" come to the CDN and not the end application. I've also worked with applications serving from Nginx or Apache to a CDN (in both cases it was Akamai), and today I work with an application that serves static files from CherryPy directly to a CDN (Amazon CloudFront). Both styles work well, what matters the most in all of these cases are the quality and features of the CDN. Anyway, the issue happens in any environment, so it needs a fix either way :-) |
@diogobaeder Sure :) Thank for explaining your use case though.
@asvetlov Yeah, especially, considering that the old way of doing things (using My solution would be to dup the socket, write headers to the duped socket using |
Thanks, guys, you rock! :-) |
@1st1 writing into socket by |
We'll have the same problem since libuv doesn't support sendfile for transports. Maybe it is an anti pattern, but you're trying to use syscalls that asyncio does not support and it just happens to work properly. While writing headers manually will involve some low level coding, it's the only solution that will work now and for months to come. |
Just like to put in my $.02 as well. This affects me, and yes I hope to use this in production. I am running an app with gunicorn + aiohttp with uvloop worker right now, I am hoping to add an "admin panel" to the app. Why am I serving with aiohttp instead of nginx/some other server? simple, its an admin panel, not being used by customers, and it makes more sense to deploy it with the backend service. |
I'll try to implement @1st1 suggestion for writing headers part without using transport. |
Thanks a lot, Andrew!
|
* Add failed test for #1093 * Put prepare under implementation methods * Manually send headers before sendfile call * Force non-blocking mode for duplicated socket * Add test for future cancellation in file sender
Fixed by #1122 |
Python/3.5.2 aiohttp/0.22.5 uvloop==0.5.2
Run this code:
Run the following command:
Headers come after file.
The text was updated successfully, but these errors were encountered: