New Toronto Group
 - New Toronto Group

Safari Browser Crash while using WebSocket

| Posted on March 26th, 2014 by Ronak Nagda


Safari

Recently, I was pulling out my hair facing a dilemma wherein the WebSocket connection was lost on an inactive Safari tab while using an iPad. First impression was a bug caused by Socket.IO. Upon investigation, I found that this was not the case, as every web socket connection was crashing and there was no way to detect this.

Issue:

Upon deeper analysis, I gathered the following information:

The WebSocket Connection Loss issue is 100% reproducible and affects the Safari browser irrespective of the application environment.

Following is the simple description along with the steps to reproduce:

  1. Visit the page which connects to a WebSocket server.
  2. Switch away from the current tab/page.
  3. The WebSocket connection will stay open for some specific time. After 90 seconds (in my case) the connection will be closed by iOS automatically.
  4. Switch back to the previously visited tab/page and the Connection will be lost OR Safari will crash.

Further research revealed that this is a known issue as many developers have complained about this problem. As far as I understand, Apple does not believe the problem exists and hence they haven’t made any changes to fix this issue that I am aware of. My best guess is, Safari is dropping the socket connection for device efficiency and resource optimization.

Workarounds:

  • One of the possible ways to avoid this scenario is to detect iOS Safari browser and prevent WebSockets on them by rather using other transport methods. That may not be viable though.
  • Another solution may be to apply a WebSocket timer while trying to reconnect within the specific time interval. Not a good solution either.

I would love to hear any fixes being rolled out in future for this one. Opinions on other effective workarounds you’ve used are welcome.

Browsers & Environments:

The issue was consistently reproducible on Safari browser run on iOS 5, 6 and 7 on iPads.

Interestingly, NO such issues were recorded on:

  • iOS running Chrome
  • Mac using Safari
  • Windows tablet running IE
  • Windows tablet using Chrome
  • Windows laptop using Chrome, IE, Mozilla

Posted in apple, javascript, Safari, Socket.io, Loading...  | Comments (0)

Comments (0)


Add a Comment





To use reCAPTCHA you must get an API key from http://recaptcha.net/api/getkey

Allowed tags: <b><i><br>Add a new comment: