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

Bug: StaticRoute returning old file contents #628

Closed
imbusy opened this issue Nov 8, 2015 · 16 comments
Closed

Bug: StaticRoute returning old file contents #628

imbusy opened this issue Nov 8, 2015 · 16 comments
Labels

Comments

@imbusy
Copy link

imbusy commented Nov 8, 2015

I am running aiohttp in an Ubuntu Docker container within a Vagrant (VirtualBox) CentOS 7 VM within Windows 8.1. The static files are served from a mounted directory in the CentOS VM, which is again a synced folder to a Windows directory.

This setup causes old file contents to be served even though the date-modified and content-length headers are correct.

The immediate fix is not to use add_static on the router, but do this:

static_route = web_urldispatcher.StaticRoute(None, '/static/', '/home/web/static/')
static_route._sendfile = static_route._sendfile_fallback
app.router.register_route(static_route)

Bug is present in v0.18.3, but I'm not sure which part of my setup is to blame.

@asvetlov
Copy link
Member

asvetlov commented Nov 8, 2015

I suspect you've caught filesystem desynchronization effect between Docker, Vagrant and Windows.
After tiny delay you are able to get required file content, isn't it?
P.S. You software stack is not looking production ready :)

@imbusy
Copy link
Author

imbusy commented Nov 8, 2015

If you're talking about a delay of ~20mins, you might be right. I got the files to refresh once, but when it happened again, I investigated further. The files are fine if I "cat" them in the Docker container.

This is obviously for development :). I would not use aiohttp to serve static files in production. And that makes it an even more important bug, because files while developing change so frequently.

@asvetlov
Copy link
Member

asvetlov commented Nov 8, 2015

Sounds bad.
Well, we can add an option for switching off sendfile capacity even if it's available.
I cannot reproduce the issue on Linux box BTW

@jashandeep-sohi
Copy link
Contributor

Mhhh...this is an odd bug.
So @imbusy, after you cat the file, does aiohttp starting serve the new content?

@imbusy
Copy link
Author

imbusy commented Nov 9, 2015

@jashandeep-sohi , no, it still serves the old file.

@imbusy
Copy link
Author

imbusy commented Nov 9, 2015

My guess what's happening: after saving a file, a new file may be created, but the old file handle still kept open by some process. When requesting the file handle ID, the old file handle ID is returned and the old file contents are served. This is just a guess. I am not an expert on Linux system internals.

@jashandeep-sohi
Copy link
Contributor

That's what I was thinking too, but I don't think Python caches the file object returned by open("/path/file.dat", "rb") (or the file handle referenced by that object). aiohttp creates a brand new file object & thus a new file handle on every request, so I don't quite understand how it might be holding on to the old handle.

But it seems the problem even affects ningx, so aiohttp is not alone:
fideloper/docker-nginx-php#17

@asvetlov
Copy link
Member

asvetlov commented Nov 9, 2015

It cannot be aiohttp or python issue because the code always open new file
descriptor by given filename on every file transfer.

Thus we have 2 options:

  1. Leave the issue as wontfix
  2. Support downgrading to not using sendfile even it is available, add to
    doc a cryptic message like "If you use docker on windows the option may
    help you somehow, forgot about the option otherwise".

@jashandeep-sohi
Copy link
Contributor

@asvetlov I propose StaticRoute should fallback to sendfile_fallback if environment variable AIOHTTP_SENDFILE is set & equal to 0.

@asvetlov
Copy link
Member

asvetlov commented Nov 9, 2015

Environment variable sounds good but I'm inclining to AIOHTTP_NOSENDFILE=x

@jashandeep-sohi
Copy link
Contributor

Yea, that's better.

@asvetlov
Copy link
Member

asvetlov commented Nov 9, 2015

@jashandeep-sohi would you provide a patch?

@jashandeep-sohi
Copy link
Contributor

@asvetlov Yea, tomorrow.

BTW, apparently this is a well known bug for VirtualBox, with the recommended "fix" being "turning off sendfile". I wouldn't call that "fix".
https://www.virtualbox.org/ticket/12597
https://www.virtualbox.org/ticket/9069

@asvetlov
Copy link
Member

asvetlov commented Nov 9, 2015

Yes, it's not a fix but workaround for virtualbox bug

@asvetlov
Copy link
Member

Fixed by #629

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants