30

My host machine is ArchLinux and I'm running Apache in a CentOS guest. I have the vhost configuration and all the site code in a shared folder. To be able to put the vhost configuration in a shared folder I mounted the shared folder as apache:apache.

shared    /mnt/shared    vboxsf    defaults,uid=48,gid=48  0 0

When I'm editing files in the host, Apache will consistently start sending old versions of the file with trailing characters. In vim, they show up as ^@, so I guess they're null characters. The number of null characters is related to the number of changes I make even if I edit the first line, null characters show up at the end. If I were to speculate, it looks like a bad diff.

If I stop httpd, umount, remount, and start httpd the file looks fine. Just restarting httpd doesn't help.

How would I go about debugging the mount? Nothing jumped out at me in /var/log.

3

3 Answers 3

53

I was wrong; it was happening elsewhere but I noticed that it was only with .css and .js files. A search led me to this post which talks about a problem with vboxsf and small files.

The solution is to set, in Apache

    EnableSendfile off
2
  • This didn't work for me. However, if I open the file in vim on the VM and save it as-is, it will work after saving it on the VM. Any other ideas? Feb 12, 2014 at 23:35
  • 2
    For completeness: in Nginx config it's "sendfile off;" Aug 7, 2014 at 9:30
2

On lighttpd the solution is to add the below line to lighttpd.conf

server.network-backend = "writev"

See: Lighttpd broken when serving from Virtualbox shared folder

1
  • YOU ARE A HERO!
    – H2ONOCK
    Apr 25, 2017 at 14:57
1

To answer the specific question "how do I go about debugging the mount":

(the below is paraphrasing, based on an investigation I just did into a problem caused by the same bug in Virtualbox, but with a different web server)

After diagnosing the problem is happening somewhere in how Apache reads files inside the virtual host, I would use "strace -p" inside the virtual host to log system calls by Apache.

While stracing, request just the one truncated/corrupted file.

Careful diagnosis will reveal that it is correctly stat'ing the file to get its length. And then it is serving it using the sendfile syscall. Basically confirming sendfile is misbehaving, meaning it must be a bug in the virtual machine.

Searching for "sendfile virtualbox" takes you to these bugs.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.