Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Reconnect sockets on iOS when resuming from background #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Mbaize
Copy link

@Mbaize Mbaize commented Feb 7, 2017

This fixes a bug which prevented resuming of playback when an iPad is locked during the playing of a video. When the iPad was subsequently unlocked the video would not resume playing even when the play button was tapped.

This fix restarts any sockets that had been in use without having to reinitialize the GCDWebServer.

This allows playback to be restarted, and GCDWebServer doesn't have to be reinitialized.
@swisspol
Copy link
Owner

swisspol commented Feb 7, 2017

It sounds like expected behavior on iOS: did you see README section on background? I think it's the same as locking iPad.

@EricJones89
Copy link

There appear to be subtle differences between locking the device and simply backgrounding the app. We do not experience any issues when backgrounding the app. However, when locking the device, you can get the sockets that GCDWebServer uses into an error state.

This only happens in two specific conditions.

  1. The server is running, but there are no active connections. The user then locks the device. When the app comes back to the foreground the server will not work.
  2. The server is running, and there are active connections. The user then locks the device. While the device is locked, the user then stops making active connections. When the app comes back to the foreground the server will not work.

In both cases GCDWebServer is required to be stopped and restarted by the user before any requests will be processed. This pull request automatically resets the sockets so that the server can be used normally.

@EricJones89
Copy link

Any thoughts on this @swisspol? We can always fork and make the changes there if you're thinking these are too particular of use cases. We simply thought it would only be beneficial to the larger community to have these.

@swisspol
Copy link
Owner

This is an important change I need to think about. Unfortunately, I do not have the bandwidth to look at it these days - very busy on other projects...

@EricJones89
Copy link

Ok, I think for now we are going to fork it and apply the changes. If you do end up pulling this in just let me know so we can come back. Thanks for the great repo!

@chrisballinger
Copy link

@EricJones89 We are also experiencing this bug, but haven't tried the patch yet. Will report back tomorrow.

@swisspol If you're swamped, would you be open to adding some volunteers? I maintain a few other libraries and could chip in occasionally.

@swisspol
Copy link
Owner

@chrisballinger Between work and family I have indeed close to zero time for GitHub open source projects these days, so helped would be welcome. I have to be honest though the code quality bar is high in this project and it's quite popular so any change needs to be considered very carefully.

@chrisballinger
Copy link

@swisspol I maintain a few popular libraries like CocoaAsyncSocket, XMPPFramework, and KissXML and have worked with contributors to improve their PRs to maintain code quality and increase test coverage.

I have limited time myself, so for GCDWebServer I would only have bandwidth to focus on merging small bug fixes and would still need to defer larger changes to you. Perhaps there are other high profile users of this library that would be able to volunteer?

@swisspol
Copy link
Owner

@chrisballinger Sounds great! Thanks much for volunteering. I just added you as a collaborator. Would I would prefer that you create a "chris" branch or equivalent, merge PRs into it and then I can have a look at that branch and give final greenlight after a couple weeks or something.

@davidchiles
Copy link

We're having this same issue.

  1. Server is working fine after fresh launch.
  2. App goes in background (lock screen) for 3+ minutes.
  3. Unlock phone.
  4. Server no longer works.

I tried this pull request and it did not solve our problems. I'll post here if I find anything else.

@davidchiles
Copy link

So maybe I don't have the same problem just the same symptoms.

We had GCDWebServerOption_AutomaticallySuspendInBackground set to NO. By removing this it fixed our issue. 🤷‍♂️

@davidchiles davidchiles mentioned this pull request Mar 1, 2017
@macrozone
Copy link

macrozone commented Jun 6, 2017

I can also reproduce this with a meteor-app which uses GCDWebServer:

meteor/meteor#8763 see reproduction 2

Edit: I will try to apply this fix to see whether it solves our issue

edit2: it solves our issues as well

@RealHandy
Copy link

Any news on the Meteor fork changes being included into this? The version Meteor is using is two years old and I can't tell whether the fixes there got into here. Thanks!
meteor/cordova-plugin-meteor-webapp#83

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

Successfully merging this pull request may close these issues.

7 participants