[SOLVED] iOS app crashes from Broken Pipe

Hi, overall MOE is awesome and the support here is great. I’ve read through several topics that have helped me port my existing apps from RoboVM to MOE and this is the first time that I’ve encountered something that couldn’t find the answer to online or figure out myself.

So I’ve ported my app and it runs great for the most part but I started getting random crashes that produced no crash log. A little googling led me to realize that there isn’t a crash log because the source of the crash is:

Mar 29 14:24:04 iPhone com.apple.xpc.launchd[1] (UIKitApplication:com.xxxxxxx.xxxxxxxx[0xa5b9][392]) <Notice>: Service exited due to signal: Broken pipe: 13

And apparently that signal doesn’t generate a crash log in iOS. I found an apparent fix here https://forums.developer.apple.com/thread/52744 but that’s where the problem lies. My app is using both java.net and com.squareup.okhttp3 (3.4.1) from several background threads to do the networking. I think the okhttp3 networking is what’s experiencing the broken pipe. I’m not sure how these map onto native iOS classes or where I would even need to apply the SO_SIGNOPIPE option mentioned in the link.

Now I know the broken pipe is probably a server problem but I don’t have control of the servers I’m contacting, so I’d like to just be able to gracefully handle the broken pipe and start another connection without it crashing my app.

Any ideas on what the problem could be here? I’m pretty sure I didn’t have this problem with RoboVM, or at the very least it wasn’t as persistent as it is now with MOE. I can pretty much guarantee a broken pipe now within the first few mins of using my app, which didn’t happen previously.

So my main questions:

a) Is there any way to catch and handle the broken pipe without crashing the app? I’ve tried Foundation.NSSetUncaughtExceptionHandler for native and Thread.setDefaultUncaughtExceptionHandler for Java, but neither stopped it. I also tried without both of them, no luck.

b) Is there at least a way to apply the SO_NOSIGPIPE option so that I can get a useful crash report from these errors?

c) This is somewhat unrelated, but I’m not getting the nice console crash details like I did with RoboVM. I used to get something like

*** Terminating from blah blah exception for this reason:

but now it rarely spits out anything about native crashes to the console. Any way to get that back?

Thanks!

Ok so I figured this one out after finding this Native crash on awake and this https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/CommonPitfalls/CommonPitfalls.html

So I just needed to find the MOE version of

signal(SIGPIPE, SIG_IGN);

which is

Globals.sigignore(13);

I just added this to my applicationDidFinishLaunchingWithOptions and no more broken pipes! At least no more crashing from broken pipes, which is good enough for me.

MOE is Amazing!!! I was getting the same issue for weeks and I could not found useful doc online. My app was always crashing because of the "The connection was broken. It was probably closed by the client. Reason: sendto failed: EPIPE (Broken pipe)
"
But using Globals.sigignore(13); inside the applicationDidFinishLaunchingWithOptions method did solve my issue on both java and kotlin projects.

Thanks for the investigation :slight_smile:

and Bravo MOE and community for the great work !