0

With Safari 7.0 for Mac OS X 10.9 Mavericks (specifically 9537.71), a web app that I work on started to have intermittent failures for Ajax requests through jQuery. This was never something that I was able to reproduce with Safari 7.0.

Environment:

  • Rails 4.0.0 (also 4.0.1)
  • jQuery Rails 3.0.4
  • jQuery 1.10.2

Request Details:

  • Uses UJS
  • Uses SSL
  • Not cross domain
  • The settings passed to the ajax:beforeSend UJS event are here.

Intermittent Error

The ajax:error UJS event was triggered when the request failed. The error message was SyntaxError: JSON Parse error: Unexpected EOF. The XHR would have ready state of 4 with an empty response and status of 200. There's indication that this is due to the browser rejecting the request since it doesn't conform to the same-origin policy. This was in line what I saw on the server side — nothing. There was no matching request for the client IP that experienced this error; the AJAX request never made it to the server. Contrary to the idea of this being related to same-origin policy, though, these requests were made relative to the host (/some/url) so it absolutely should not fail the same-origin policy test & should not be subject to cross domain rules. Also, if this were related to a cross-domain issue, one would expect consistent failures. Interestingly, this seemed to happen consistently for certain users, but there were cases of them re-trying and things working properly later.

This issue happened for about 30% (ballpark) of requests with this specific version of Safari. It never happened with any other browser. This is a pretty critical part of the app, so I've been trying a slew of workarounds to what I'm assuming is a browser bug, but have yet to find any reports of such an issue.

Attempted Fixes

Attempted fixes without success:

  • Originally the page's GET and POST URLs were the same, so I tried having the request post elsewhere.
  • I tried making the URL absolute instead.

These attempted fixes did not change anything.

Also, in diagnosing this problem, I used a basic AJAX request to post errors back to the server and get better reporting on what was going on. I noticed that some of these requests were failing as well (partial error reporting still helped in troubleshooting). So overall, it didn't seem like anything directly related to Rails, jQuery, or UJS.

JSONP Solution?

Finally, I switched the request to use JSONP today, and it's been pretty successful. There was one failure, but that failure could have been for other reasons (still investigating).

Question

My questions:

  • Is there any known instance of this happening?
  • Is there any explanation for this other than a browser bug (what am I overlooking)?

I'll be submitting a bug report to the WebKit team as well, but wanted to ask here in case anyone has any thoughts.

Community
  • 1
  • 1
wbyoung
  • 22,383
  • 2
  • 34
  • 40

1 Answers1

0

Updating my web server from Lighttpd 1.4.26 to 1.4.33 fixed this problem.

The problem seems to have been in the web server. I don't know if it was a bug in the server or not (I didn't find any reports), but I was able to reproduce the issue by running a minimal configuration and sending POST requests to it. Simple POST requests from a form failed to make it through through to the web server properly.

Here's the installation I was running:

Ubuntu 10.04.4 LTS (lucid)  
lighttpd/1.4.26 (ssl) - a light and fast webserver
Build-Date: Dec 20 2011 14:45:35

Event Handlers:

  + select (generic)
  + poll (Unix)
  + rt-signals (Linux 2.4+)
  + epoll (Linux 2.6)
  - /dev/poll (Solaris)
  - kqueue (FreeBSD)

Network handler:

  + sendfile

Features:

  + IPv6 support
  + zlib support
  + bzip2 support
  + crypt support
  + SSL Support
  + PCRE support
  + mySQL support
  + LDAP support
  + memcached support
  + FAM support
  + LUA support
  + xml support
  + SQLite support
  + GDBM support

After building a new version of Lighttpd, I'm running:

lighttpd/1.4.33 (ssl) - a light and fast webserver
Build-Date: Dec  8 2013 14:06:46

Event Handlers:

    + select (generic)
    + poll (Unix)
    - rt-signals (Linux 2.4+)
    + epoll (Linux 2.6)
    - /dev/poll (Solaris)
    - eventports (Solaris)
    - kqueue (FreeBSD)
    - libev (generic)

Network handler:

    + linux-sendfile
    - freebsd-sendfile
    - solaris-sendfilev
    + writev
    + write
    - mmap support

Features:

    + IPv6 support
    + zlib support
    + bzip2 support
    + crypt support
    + SSL Support
    + PCRE support
    - mySQL support
    - LDAP support
    - memcached support
    - FAM support
    - LUA support
    - xml support
    - SQLite support
    - GDBM support

Maybe this will save someone else some time, but there probably aren't a lot of people still running this old version of Lighttpd.

wbyoung
  • 22,383
  • 2
  • 34
  • 40