Restore SIGPIPE default handling for port children #4905
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While answering this stackoverflow question I noticed that the default handling for
SIGPIPE
inopen_port
children was set toSIG_IGN
.After a little investigation, I found that it's set as such in
sys_drivers.c:erl_sys_late_init
, and inherited through thefork()
s.This is a problem because if the port owner dies, the pipes attaching the port to the children (the external command) break and the children may not notice it.
The problem arises when the spawned command has no knowledge about this behaviour and ignores the
EPIPE
when writing or reading from the port's FDs, as the spawned command may rely on the SIGPIPE to terminate and ends orphanded instead.In this commit, the behaviour is reset to the default just before
exec
is called in the children. BUT this is a breaking change. Any external command that knowingly (or unknowingly) relied on not being killed when reading from these file descriptors would be killed after this change.Example
This behaviour can be tested with the following codes:
Both
dot
andwatch date
will get orphanded before this change whereasdot_sigpipe_dfl
will terminate correctly regardless.Alternatives
As an alternative solution, I'd allow providing some sort of signal action option in
open_port
, but it'd be strange to have an spawned command with signal handling that's not default. If it's decided that this is too breaking, I'd add it to the documentation at least.