As regular readers may realize, I have had problems with it crashing with no messaging. The last two nights, it crashed in a write call with a SIGPIPE signal.
Now, I don't routinely trap signals for the same reason that
catch (Exception) is a bad idea, namely they generally mean something bad happened and everything needs to stop so it can be fixed. There are exceptions to this rule of thumb of course, but generally it's no bueno.
Back to the problem... The reproduce steps are easy to deduct, at this time of year, instead of turning the outside lights on at sunset, I turn the outlets controlling the outdoor Christmas decorations on. Then, at 2130, I turn them off and turn the outside lights on. The reason for the relatively early switch is that the Christmas decorations shine in through my daughter's bedroom window. Once school is out, I will switch them over later. Anyways, at 2130, there is a flurry of activity on the network thread, as it receives the "off" and "on" commands to make the switch over happen. It is in this flurry that plcd crashes.
SIGPIPE can arise when writing to a socket that has been closed, which is entirely possible with 'plccommandline' as it opens the socket, fires the command closes the socket and terminates. Under most circumstances I reckon that the socket is open long enough to send the 'END::' response from the server, however, as there is another instance of 'plccommandline' executing at the same time, perhaps this is slowing things down just enough to get the socket closed before the response can be sent.
The fix will be relatively simple, instead of using 'write' I will use 'send' which takes an additional parameter, a set of flags. One flag that can be set is to turn off the potential SIGPIPE, this is what I plan on setting. As setting this flag disables raising the signal, I don't need to use a signal handler to do handle it, nor do I need to worry about mulitthreaded use of the signal handler. Perhaps this is the source of my random crashes! I am quite excited to see this problem, and how it is so easily reproducible, and hopefully making it go away will be a simple thing too.