zig icon indicating copy to clipboard operation
zig copied to clipboard

os.write on a closed socket triggers SIGPIPE

Open truemedian opened this issue 5 years ago • 4 comments

Calling os.write() on a peer-closed socket without the MSG_NOSIGNAL flag triggers a SIGPIPE, rather than return an EPIPE errno.

truemedian avatar Jun 15 '20 21:06 truemedian

Would the right thing to do be to set MSG_NOSIGNAL by default on network sockets? I just ran into this, seems like a horrible default behavior to have a network program exit without any message when the remote end closes

ghost avatar Oct 04 '22 17:10 ghost

Correct, the best thing to do by default on network sockets is MSG_NOSIGNAL

IridescentRose avatar Nov 05 '22 03:11 IridescentRose

I was asking if the stdlib should set it automatically, but I just realized it seems to be Linux-specific... there seems to be no equivalent to the MSG constants on windows for example.

ghost avatar Nov 05 '22 09:11 ghost

Windows doesn't have SIGPIPE. It does the equivalent of MSG_NOSIGNAL and returns the windows version of EPIPE (BROKEN_PIPE).

This doesn't break on windows because it doesn't need to do this.

truemedian avatar Nov 05 '22 15:11 truemedian