Javascript unexpected errors

Today while working on a mini-project, I encountered some problems with JavaScript, notably:

Unexpected end of input
Unexpected token illegal

Oddly, the source file had barely changed (new line, for example) and there was no apparent error. Also, sometimes the file received seen through Chrome Developer Tools didn’t reflect the changes made on the source.

After searching around for a bit, I found this post in StackOverflow which brings to this post, where it appears to be a problem with VirtualBox and its use of the sendfile() function.

The problem appears when using shared folders through VirtualBox, and the fix is to add the following directive to your site description:

For nginx:

sendfile off;

For Apache:

EnableSendfile Off

Extract from the Apache docs:

This directive controls whether httpd may use the sendfile support from the kernel to transmit file contents to the client. By default, when the handling of a request requires no access to the data within a file — for example, when delivering a static file — Apache uses sendfile to deliver the file contents without ever reading the file if the OS supports it.

This sendfile mechanism avoids separate read and send operations, and buffer allocations. But on some platforms or within some filesystems, it is better to disable this feature to avoid operational problems:

  • Some platforms may have broken sendfile support that the build system did not detect, especially if the binaries were built on another box and moved to such a machine with broken sendfile support.
  • On Linux the use of sendfile triggers TCP-checksum offloading bugs on certain networking cards when using IPv6.
  • On Linux on Itanium, sendfile may be unable to handle files over 2GB in size.
  • With a network-mounted DocumentRoot (e.g., NFS or SMB), the kernel may be unable to serve the network file through its own cache.

For server configurations that are vulnerable to these problems, you should disable this feature by specifying:

EnableSendfile Off

For NFS or SMB mounted files, this feature may be disabled explicitly for the offending files by specifying:

<Directory "/path-to-nfs-files">EnableSendfile Off</Directory>

Please note that the per-directory and .htaccess configuration of EnableSendfile is not supported by mod_disk_cache. Only global definition of EnableSendfile is taken into account by the module.

Nginx also has reference to this:

This entry was posted in WebDev and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.