-
Notifications
You must be signed in to change notification settings - Fork 18k
os/exec: broken pipe writing into djpeg #9173
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 mentioned the JPEG structure but didn't elaborate: I have a theory that the JPEG has some extra AppMarker segments at the end which don't contribute pixels to the image. So djpeg stops reading when it's done with the pixels, does its resizing and writes its output images and ends the process, without reading the extra junk at the end of the JPEG. |
@ianlancetaylor, any wisdom here? |
Don't be misled by the SIGPIPE in the strace output. Nothing is happening because of that signal. It is caught and ignored. In the os/exec package, the io.Copy call in Cmd.stdin is returning an EPIPE error. That is the error being reported by the call to the Wait method. The name of the write side of the pipe is "|1" (from os.Pipe). The error is an os.PathError generated by os.File.Write, called by io.Copy. I think that your suggestion of ignoring an EPIPE error in os/exec.stdin is reasonable. Cmd.Wait will already only return that error if the program exited successfully. In that scenario, returning EPIPE conveys little useful information. Or, we could document the behaviour. Most C programs in this situation will receive the SIGPIPE signal, fail to handle it, and exit. In a shell pipeline, nothing much will happen, because the shell will use the exit status of the final process in the pipeline. If you do this, using bash: set -o pipefail you will see that the cat program died due to a SIGPIPE signal. If you do this: trap "" PIPE then the cat program will not get a SIGPIPE signal, but will instead fail because write returned EPIPE. cat: write error: Broken pipe Anyhow, the only real question is whether we should return the EPIPE error from os/exec, or just drop it. Personally I think it would be fine to drop it. That is the natural implementation of the default behaviour of shell pipelines. |
Excellent, thanks. I'd prefer to drop the error then. I'd prefer people go out of their way to get the failure for the weird case. |
See golang/go#9173 which has been added to Go >= 1.5. If the subprocess for whatever reason (like exiting) closes stdin without reading it the caller (cni) will get an EPIPE error even if there was valid output and the subprocess finished successfully. Since Go >= 1.5 will be ignoring this error, we need to compensate for older Go versions.
Attachments:
The text was updated successfully, but these errors were encountered: