-
Notifications
You must be signed in to change notification settings - Fork 18k
os/exec: cmd.Start got a deadlock when set cmd.Stdin #47061
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
Comments
I can't reproduce this, this exits normally on my system |
Hi, @seankhliao do you modify golang source code in /usr/local/go/src/syscall/exec_unix.go like the picture. Child process build with the original source code, parent process build with the modified source code. parent process hang on wait4 child process wait on reading pipe |
Please describe code as ordinary text or as links to the Go source code. Please do not use images. Images are hard to read. Thanks. |
I can't recreate this problem either. I see this output:
There is a ten second delay after the final "child log" output. |
and then build parent code with the changed source code
Could you please try these steps again, @ianlancetaylor @seankhliao , thanks |
I don't understand. Are you saying that this problem only happens if you change the standard library? Doesn't that mean that there is a bug with the way that you are changing the standard library? I haven't tried to fully understand what you are doing, but it sounds like you are changing the code so that the child runs but the parent thinks that it did not run. Why do you expect that to work? |
It is my fault not describe the timing at this case happen, it was happened online much times. I read the source, found that when the code goes into the error handling logic, it will hang forever. Since I can't reproduce in offline test environment, to verify my guess, I change the source code to reproduce the error case, and it show the same error as online. So I ask here to see if some one can help me. Since it really happens online, and the stack dump online is just like the picture I post, I think it is a deadlock in source code, through I not found the root case about why child process run, but the code goes into the error handling logic. Do you need more information, @ianlancetaylor |
The fact that you get the same stack trace doesn't mean that you are seeing the same problem. The parent and child cooperate to report status. By using different code for the child and parent, you are reaching a case where the child succeeds but the parent think that is has failed. The parent then waits for the child process to complete. If the child process had in fact failed, that would be fine. But in your case the child process has not failed, so the parent waits forever. I don't know what the real problem is, but as far as I can tell your example is showing a different problem that happens to have the same stack trace. We need to fix the real problem, not the problem that you are describing. |
Yes, you are correct, I am not describe this problem clearly, I just found this maybe got a error after child process create successfully, as child need read stdin to finish, so both child and parent process hang. But I can't found any other information, any idea for debug this, @ianlancetaylor ? |
It's hard to know what to suggest without seeing the real code. Typically approaches would be for both the parent and the child to print out before and after they make an I/O call, so that you can see where the hang occurs. Or sometimes it helps to run the program under |
The big problem is unable to reproduce offline, online environment I can only see the hang case. from the stack, I think the most probable error is |
Why do you think that the problem is in What is the real problem? The stack traces above show that the parent process is hanging in |
No new information |
What version of Go are you using (
go version
)?$ go version
go version go1.15.11 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
There is a deadlock in cmd.Start, this is only happen when command set cmd.Stdin
the calling stack: cmd.Start -> cmd set stdin, add stdin io copy in a goroutine after os.StartProcess successfully -> begin os.StartProcess -> finally in forkExec() -> fail in readlen (donnot know why) -> deal with the fail, begin to call wait4, but child process has run successfully, child wait goroutine to copy io, it was hang, and wait4 never success
use the follow code to reproduce
parent
child
Since I donnot know why readline fail, so I modify source code, create a error after readlen, make it fails
What did you expect to see?
cmd.Start got a error return
What did you see instead?
Both parent and child process were hang forever
The text was updated successfully, but these errors were encountered: