Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket.io crashes Mobile Safari on iOS #976

Closed
brianlukoff opened this issue Jul 31, 2012 · 33 comments
Closed

socket.io crashes Mobile Safari on iOS #976

brianlukoff opened this issue Jul 31, 2012 · 33 comments

Comments

@brianlukoff
Copy link

I am having an issue with Mobile Safari crashing on iOS. The following will consistently reproduce a crash for me:

  1. Load a page in Mobile Safari that connects using socket.io.
  2. Click the "change tab" button and navigate to a different tab to put the current tab in the background.
  3. Send a message from the server to the client.
  4. Navigate back to the original tab (the one that connected via socket.io). Mobile Safari crashes.

I think it is related to this:
https://gist.github.com/2052006
The page above includes a workaround, but I'm not sure how to implement this workaround with socket.io.

@brianlukoff
Copy link
Author

I should add that between #3 and #4 above you should wait a minute or so for the connection to time out.

@rauchg
Copy link
Contributor

rauchg commented Jul 31, 2012

Is this using Websocket?

@brianlukoff
Copy link
Author

Yes, the client is making a Websocket connection to the socket.io server.

@rauchg
Copy link
Contributor

rauchg commented Jul 31, 2012

Yep we've gotten several reports of Mobile Safari crashing. We should add user agent sniffing to the websocket feature detection to exclude it unfortunately. Thoughts @3rd-Eden ?

@rauchg
Copy link
Contributor

rauchg commented Jul 31, 2012

Can we narrow it down to a specific Mobile Safari or is it all?

@brianlukoff
Copy link
Author

I'm seeing the crash on 5.1; haven't been able to try it out on other versions.

@3rd-Eden
Copy link
Contributor

We already patched the issue in the supplied gist: socketio/socket.io-client@8dc031d

@rauchg
Copy link
Contributor

rauchg commented Jul 31, 2012

Wait so why is this still happening?

@3rd-Eden
Copy link
Contributor

Are you running on Wifi, 3g, or using any proxy settings in your network?

@3rd-Eden
Copy link
Contributor

What version of socket.io are you using? I don't see that in the supplied bug report. Same with iOS version.

@brianlukoff
Copy link
Author

Thanks -- I was on 0.9.6 and upgraded to 0.9.8 and the issue went away. Sorry about that -- didn't realize it had been fixed in the interim.

@debianw
Copy link

debianw commented Jul 1, 2013

This issue is still happening with v 0.9.16.

Steps to reproduce:

  1. Create a simple hello word socket.io implementation
  2. Create a phonegap 2.x project and wrap your index.html file into the www folder.
  3. Run the project then sleep the device
  4. After a couple of minutes then resume and you'll see the app crash.

Environment:

  • Socket.io v0.9.16
  • iOS 6.1.3
  • phonegap 2.x

More info about the crash info: #1210

@fernandopg
Copy link

The exact same problem!

Socket.io v0.9.16
iOS 7.0
phonegap 3.1.0

Any fix?

Thank you!

@rauchg
Copy link
Contributor

rauchg commented Dec 13, 2013

Is this only with phonegap?

@3rd-Eden
Copy link
Contributor

@guille could be because phonegap runs in a webview which has different restrictions than a regular safari. I wonder if Chrome for iOS also exhibits the same issues as it also runs in a webview.

@debianw
Copy link

debianw commented Dec 13, 2013

only on phonegap for me. The problem is when the device goes to sleep mode for a while and then resume. Our workaround was to disconnect and reconnect the socket manually listening to the resume and pause phonegap events.

@cayasso
Copy link

cayasso commented Dec 13, 2013

@fernandopg If this helps on your PhoneGap pause event do a disconnect() then on your resume event do a socket.reconnect() on the socket. Here is some code, notice that the reconnect is on the socket object it self, this solved the problem for us as @debianw mentioned.

var conn = io.connect(url);

function pause() {
  conn.disconnect();
}

function resume() {
  conn.socket.reconnect();
}

// Assign function to as corresponding phonegap events listeners.

@fernandopg
Copy link

Seems to work! I tried this in older versions of phonegap and didn't work but now seems to work! Thanks @cayasso !!!

@cayasso
Copy link

cayasso commented Dec 16, 2013

@fernandopg Awesome!!!

@ghost
Copy link

ghost commented Dec 20, 2013

Thanks @cayasso. Do you need to disable the socket.io reconnect property as well?

@metral
Copy link

metral commented Dec 20, 2013

i'm getting the same "resume from sleep" crashes when using on the server side: node.js & socket.io (v0.10.21 from npm) and connecting to it via mobile chrome & safari in ios7 (client side which uses socket.io.js v 0.9.16).

I've had no luck nor have been able to pinpoint what exactly is taking place when it crashes. what i do know is that after i leave the mobile browser & lock the screen, node.js disconnects the websocket connection. upon resuming from sleep and reopening the mobile browser a new websocket connection is established and some data transfers from server to client, but the crash happens soon thereafter.

google hasn't been much help either, so i'm hoping someone here can guide me

@cayasso
Copy link

cayasso commented Dec 20, 2013

@blairvanderhoof No, no need to disable reconnect.

@ghost
Copy link

ghost commented Dec 20, 2013

@cayasso That's great but I thought socket reconnect was causing the crash?

@cayasso
Copy link

cayasso commented Dec 20, 2013

@blairvanderhoof yes it is in certain way, that is why we only disconnect and reconnect for PhoneGap background events leaving it intact for other regular disconnect events.

EDIT: You can always turn off reconnect but then you will have to manually handle reconnects (timing, backoff, etc) when needed.

@thewaterbear
Copy link

I'm still getting this issue, in mobile chrome.

@rauchg
Copy link
Contributor

rauchg commented Jun 12, 2014

@dchen05 with 1.0?

@rauchg rauchg reopened this Jun 12, 2014
@thewaterbear
Copy link

@guille 9.16, but I will try 1.0 and report back

@Ajaxy
Copy link

Ajaxy commented Apr 17, 2015

Having same issue with 1.2.0 and PhoneGap.

Seems that crashing may happen after calling connect on previously disconnected socket instance. I needed to modify my error handler to check if I have another instance connected. Plus I'm removing all listeners with socket.off() before disconnecting. Crashes disappeared.

                socket.on('error', function (e) {
                    var targetSocket = this;
                    **if (targetSocket != socket) { return; }**
                    socket.disconnect();
                    setTimeout(function () {
                        **if (targetSocket != socket) { return; }**
                        socket.connect();
                    }, 1000);
                });

@Ajaxy
Copy link

Ajaxy commented Apr 17, 2015

But actually what if I don't want to disconnect on app pause?

I have major feature when user sends an invitation to online match to another user and sees "waiting dialog". I don't want to make him just stop and wait, he can go to another app or home screen. And when the response from another user is recieved I can show system local notification about starting the match and ask him to bring my app back.

@rauchg
Copy link
Contributor

rauchg commented Apr 17, 2015

Can you test with latest instead of 1.2.0?

@Ajaxy
Copy link

Ajaxy commented Apr 20, 2015

Okay, I will. What about my second question? What if need active connection in background for some time?

@rauchg
Copy link
Contributor

rauchg commented Apr 21, 2015

You should basically handle reconnections appropriately. You don't have any guarantees that while you switch apps the connection will stay on anyways, due to other potential problems. Socket.IO will reconnect on your behalf automatically when you switch back.

@Ajaxy
Copy link

Ajaxy commented Apr 23, 2015

What do you mean by "appropriately"? How would you suggest to handle use case I mentioned above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants