strophe / libstrophe

A simple, lightweight C library for writing XMPP clients
http://strophe.im/libstrophe
Other
401 stars 163 forks source link

libstrophe crash caused by SIGPIPE signal #127

Closed matisszilard closed 6 years ago

matisszilard commented 6 years ago

The libstrophe library crashed on iOS caused by a SIGPIPE signal.

Please see the following scenario:

Related logs:

[Trace] : Libstrophe Log - [tls], msg [error=5 errno=60]
[Trace] : Libstrophe Log - [xmpp], msg [Unrecoverable TLS error, 5.]
[Trace] : Libstrophe Log - [xmpp], msg [Closing socket.]
[Trace] : Libstrophe Log - [tls], msg [error=5 errno=32]
[Debug] : xmpp_connection_handler - Connection Closed with error code [3]
(lldb) bt
* thread #16, stop reason = signal SIGPIPE
  * frame #0: 0x0000000114598bdc libsystem_pthread.dylib`start_wqthread

Disabling SIGPIPE solves the issue:

int set = 1;
setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int));

Question:

How should the libstrophe library handle the SIGPIPE properly?

Connected blog:

https://badrit.com/blog/2010/11/30/ignore-sigpipe-signal-on-ios#.W5ZGTC2B0sl

Connected issues:

https://github.com/strophe/libstrophe/issues/113 https://github.com/strophe/libstrophe/issues/124

pasis commented 6 years ago

What I've seen in practice is that libstrophe's users simply ignore SIGPIPE:

signal(SIGPIPE, SIG_IGN);

Also when a connection fails (instead of segfault) you can reconnect from the connection handler. But you need to understand that unsent messages will be lost and libstrophe doesn't provide a way to get the messages.

matisszilard commented 6 years ago

Thanks for the information.

Maybe it is a good idea to document somewhere that the SIGPIPE signal should be handled by the users of the library.