New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os/exec: (*SysProcAttr).Foreground causes the spawned process to hang #37217
Comments
Thank you for this bug report @miquella, and apologies that we didn't get to look at this during the Go1.15 cycle. I shall re-triage this issue for Go1.16. |
Currently we call tcsetpgrp from child thread. This causes bugs like Github issue golang#37217. We can instead call it from the parent thread, since the child pgrp is either found in the SysProcAttr or equal to the child pid.
Change https://golang.org/cl/266057 mentions this issue: |
Change https://golang.org/cl/313653 mentions this issue: |
Change https://golang.org/cl/314271 mentions this issue: |
That way the skip takes effect. Also ignore the result of calling TIOCSPGRP when cleaing up TestForeground. It has started to fail for some reason, and the result doesn't matter. Also call TIOCSPGRP to clean up in TestForegroundSignal. For #37217 Change-Id: I2e4282d7d91ad9a198eeb12cef01c2214c2a98c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/314271 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes — tried with
go1.14rc1
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
The process should execute
echo
and displayhello
.What did you see instead?
The process hangs.
ps
shows the child process as suspended and doesn't appear to have calledexecve
yet:Explanation
From what we can determine, we believe this is what is happening:
setpgid
/SYS_SETPGID
, creating a new background process group (ref)tcsetpgrp
/TIOCSPGRP
, causing the process to be suspended (ref)While a process in the foreground process group is allowed to call
tcsetpgrp
, a process in a background process group has an additional hurdle. From the man page fortcsetpgrp
:Which explains why the process is getting suspended, as the default action for
SIGTTOU
is to stop the process. This also explains when ignoringSIGTTOU
before spawning the process fixes the problem. However, this has an undesired side-effect: the subsequently exec'd process then ignoresSIGTTOU
as well.Conclusion
Unfortunately, because all of this work is done in the child fork, there is no way for Go user code to reset the ignored
SIGTTOU
before exec'ing the process.So there is no way to have a user ignore the
SIGTTOU
signal without an adverse effect on the child process.Proposal: if the
SIGTTOU
signal could be ignored for the duration of thetcsetpgrp
/TIOCSPGRP
call and restored to its prior state immediately following, we believe this would elicit the expected behavior without adverse side-effects.The text was updated successfully, but these errors were encountered: