View Issue Details

IDProjectCategoryView StatusLast Update
0001536libmicrohttpddocumentationpublic2010-07-26 23:33
Reportersquishyent Assigned ToChristian Grothoff  
PrioritynormalSeveritytextReproducibilityN/A
Status closedResolutionfixed 
Product Version0.4.4 
Summary0001536: Occasionally crashes with SIGPIPE due to client-terminated connections in Solaris 8
DescriptionI am currently using libmicrohttpd in a C++ server which is using HTTP as its primary request protocol. This server is running both on Solaris 8 on a SPARC processor and Red Hat Linux on an x86 processor. Some of the requests can take a couple of minutes before posting responses, and if the requesting client terminates the connection before the work is complete the program will occasionally crash.

I believe I have tracked the problem down to receiving SIGPIPE due to an attempt to write to a closed SOCK_STREAM socket connection. I have managed to reliably reproduce this problem in Solaris (but not Linux!) using the following steps:

1. Start with the hellobrowser.c tutorial example.
2. Add a significant delay in the request by adding a call to sleep( 3 ) to the beginning of answer_to_connection().
3. Start the server and use a web browser to load a page from it. This should work.
4. Hold down F5 to cause the browser to refresh the page many times. On one of the calls, after answer_to_connection() returns, the program receives SIGPIPE and dies (with the message "Broken pipe" sent to STDERR).

Some notes:
* Using Google Chrome on Windows XP, I was able to make this happen every time when returning from the fifth call to answer_to_connection() after six or more refreshes. This may be useless information, as I don't know when Chrome closes its connections, but fewer than six refreshes will not cause the problem to occur.
* If the program is modified to report errors, it sometimes sends the following message to the error handler immediately before dying: "Failed to send data: Broken pipe". I never see this message when the program doesn't die.

It certainly seems odd that we can get both a message in the error handler and an uncaught SIGPIPE which kills the program. This is wild speculation, but perhaps Solaris 8 is not re-registering the signal handler on the first call, and a subsequent attempt to write to the same socket causes an unhandled SIGPIPE to be sent?
TagsNo tags attached.

Activities

squishyent

2010-01-19 22:11

reporter   ~0003991

Note that if I call sigignore( SIGPIPE ) before MHD_start_daemon() is called, the issue seems to be resolved. I can refresh the page as much as I want. I will get occasional "Failed to send data: Broken pipe" errors reported, and eventually I start to see "Server reached connection limit (closing inbound connection)" errors, and life is wonderful.

I am going to add this call to my program as a workaround for the problem.

Christian Grothoff

2010-01-20 20:21

manager   ~0003992

This is not really "just" a workaround but the (strongly) suggested solution. MHD does not install a handler for SIGPIPE since, as a library, messing with signal handlers might cause problems for an app that has (conflicting) handlers installed already.

So on platforms where SIGPIPE cannot be elimianted by MSG_NOSIGNAL, MHD requires developers to install a handler. Now, the examples don't contain this -- largely to keep them simple. Still, the documentation might want to stress this point a bit more, so I'll file this bug report under "improve documentation".

NDurner

2010-01-20 22:26

reporter   ~0003993

I can't reproduce this problem on Windows Vista with Chrome and the fileserver_example.

Christian Grothoff

2010-07-26 20:12

manager   ~0004078

Issue documented in MHD manual for 0.9 (introduction, subsection 1.1).

Issue History

Date Modified Username Field Change
2010-01-19 21:24 squishyent New Issue
2010-01-19 22:11 squishyent Note Added: 0003991
2010-01-20 20:21 Christian Grothoff Note Added: 0003992
2010-01-20 20:21 Christian Grothoff Severity crash => text
2010-01-20 20:21 Christian Grothoff Reproducibility have not tried => N/A
2010-01-20 20:21 Christian Grothoff Status new => confirmed
2010-01-20 20:21 Christian Grothoff Category portability => documentation
2010-01-20 22:26 NDurner Note Added: 0003993
2010-07-26 20:12 Christian Grothoff Status confirmed => assigned
2010-07-26 20:12 Christian Grothoff Assigned To => Christian Grothoff
2010-07-26 20:12 Christian Grothoff Note Added: 0004078
2010-07-26 20:12 Christian Grothoff Status assigned => resolved
2010-07-26 20:12 Christian Grothoff Resolution open => fixed
2010-07-26 23:33 Christian Grothoff Status resolved => closed