TIL: writing to a socket and dying
Andy Valencia
dont at spam.me
Thu Apr 24 14:04:03 UTC 2025
This has been touched upon way back in forum history, but I
thought it was worth a fresh mention. When writing to a
socket--especially as a server--you can receive SIGPIPE. Phobos
appears to try and inhibit this on some BSD systems, but on Linux
if the recipient has closed the socket and you write--SIGPIPE.
And if you thought you had your bases covered with
try/catch--nope! This is a _signal_, not an exception. The
default for SIGPIPE is for your process to terminate. Why was my
server dying? The key clue was the exit code, which led me back
to SIGPIPE and then I could guess what had happened. I added a
SIG_IGN of SIGPIPE and that made the problem stop. (There's also
a flag MSG_NOSIGNAL to send() which might address this as well.)
With that, my web service middleware is running quite nicely.
SSL, authentication, files/seeking/streaming, and parallel
request dispatch.
Andy
More information about the Digitalmars-d-learn
mailing list