AsyncUDPSocket broken pipe after locking phone with application suspended in background
I'm using the AsyncUDPSocket third party library in my iPhone app and for the most part it works great. I have a singleton instance of an AsyncUDPSocket
that I use for all my network traffic. My app is registered for location tracking in the background and will wake up and send location update packet(s) over the network while running in the background. This all works smashingly running in the background, foreground, phone locked or unlocked, except when I do the following:
- Start my app
- Disable location tracking in my app settings (so no background waking up)
- Press the home butt开发者_StackOverflowon (app goes into background, socket is "freeze-dried" with rest of app)
- Lock phone
- Unlock phone
- Resume app
- Attempt to restart tracking and send something out the socket. As soon as I try, I get a
SIGPIPE
/EPIPE
error and the app crashes.
I figured the best way to deal with this would be to close and release the socket whenever the application exits and background tracking is not enabled, but when I try [socket close]
or [socket release]
on the AsyncUDPSocket
, I get various EXC_BAD_ACCESS
errors. I've filed a bug with the dev team, but was wondering if anyone here could give some ideas on how to either avoid the SIGPIPE
error entirely or other ways to keep the socket alive without releasing it. Thanks.
Great observation - yes, seems that after you send task to background and then lock the phone, sockets get dropped and next time you try to use it one gets bludgeoned with a SIGPIPE.
Ideas on how to deal with it here: SIGPIPE crash when switching background task (it's either set ignore for SIGPIPE for the whole app, or for the socket, or provide hanler for it)
ps. also - seems that setting to ignore SIGPIPE does not work with attached debugger, so compare with and w/o.
Just in case anyone's curious (which, judging by this question's stats, they're not), I was not able to determine what was causing the SIGPIPE
error, but did eventually sort out my memory management issues (which were due to a faulty implementation of onUdpSocketDidClose
in my delegate) so that I am able to reinitialize the socket each time the app restarts.
精彩评论