Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One note about sendfile - if you are using VirtualBox and serving files out of a shared folder with nginx (or I assume Apache) you'll need to disable it or you won't see any updates you do to files once the first version is sent.


This VirtualBox bug was the reason that I started reading more about sendfile and encountered this article about nginx optimizations. The bug actually causes really weird behavior, in which extra bytes are added at the end of the file.


It doesn't really add extra bytes - it "remembers" the original size of the file. So if you update the file to be larger, you only get the first N bytes. If you update it to be smaller, you get the full file + zero bytes at the end to fill out the remainder. If you can't turn off sendfile for some reason, the workaround is to delete the file every time before saving it.


Thanks, enlightening. And is this because due to some implementation difficulties for sendfile when using shared file system between the box and the host machine?


I JUST ran into this issue this weekend! Glad to know I'm not going insane.

Do you have any links specifically discussing the issue?


https://www.virtualbox.org/ticket/9069

Google for 'virtualbox sendfile' and there's a lot of discussion.

Worth noting, and this bit me recently, Go's http file handler also uses sendfile beneath the covers.


Yes, this StackOverflow answer solved the mystery for me http://stackoverflow.com/questions/12719859/syntaxerror-unex...

I then found out that it is actually mentioned in the Vagrant docs also: https://docs.vagrantup.com/v2/synced-folders/virtualbox.html


Haha omg this issue. I came across this about a year ago, and it took forever to diagnose the problem. Who would think to look for a specific declaration in the web server config? I thought for the longest time it was a problem with my host<->guest mount. Glad to see other people suffering similarly :p


Not only that, but using an nginx container on OSX with boot2docker (VirtualBox based) was actually just causing all of the static files being served to be truncated. I spent a solid day tracking that down.


This occurred with VMWare Fusion 6 as well.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: