[Live-devel] Ignoring SIGPIPE

Ross Finlayson finlayson at live555.com
Thu Apr 19 18:14:39 PDT 2012


> I have an issue on Mac OSX where the RTSPClient was throwing SIG_PIPE whenever the TCP connection from the server was terminated (server timeout or crash).
> Trying to USE_SIGNALS as below did not work and we were still crashing when the connection was dropping:
> #ifdef USE_SIGNALS
>   // Ignore the SIGPIPE signal, so that clients on the same host that are killed
>   // don't also kill us:
>   signal(SIGPIPE, SIG_IGN);
> #endif
> 
> The only way we found to fix ti was to set SO_NOSIGPIPE on the socket itself when created.
> 
> 
>   if (newSocket > 0) {
>     int set_option = 1;
>     if (0 == setsockopt(newSocket, SOL_SOCKET, SO_NOSIGPIPE, &set_option, sizeof(set_option))) {
>     } else {
>     	socketErr(env,"failed to set socket signal option");
>     }
>   }
> 
> I have attached the source code with the change in GroupsockHelper.cpp .  
> Will it be possible to include that change in an upcoming release?

No, because I don't want this behavior (ignoring SIGPIPE signals) to happen all the time.  Instead, it should happen only when the developer specifically wants it.

In this case, what we want is for the RTSP server to ignore SIGPIPE signals that might get sent when clients (running on the same host) die.  So the right place to do this is in the "RTSPServer" code, in the same place where we currently do:
	#ifdef USE_SIGNALS
	  // Ignore the SIGPIPE signal, so that clients on the same host that are killed
	  // don't also kill us:
	  signal(SIGPIPE, SIG_IGN);
	#endif

What I might end up doing, therefore, is replace this code with:
	#ifdef USE_SIGNALS
	  // Ignore the SIGPIPE signal, so that clients on the same host that are killed
	  // don't also kill us:
	#ifdef SO_NOSIGPIPE
    	int set_option = 1;
	setsockopt(ourSocket, SOL_SOCKET, SO_NOSIGPIPE, &set_option, sizeof set_option);
	#else
	  signal(SIGPIPE, SIG_IGN);
	#endif
	#endif

I hope this will work for you...



Ross Finlayson
Live Networks, Inc.
http://www.live555.com/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20120420/4b695d8b/attachment.html>


More information about the live-devel mailing list