You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OS Version/Architecture: 10.0-RELEASE-p6 FreeBSD 10.0-RELEASE-p6 #0: Tue Jun 24 07:47:37 UTC 2014 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64
I'm trying to pipe arbitrary strings to an external command which sometimes hangs for some reason.
I want to get the CombinedOutput of the command after executing.
The application hangs while piping.
I investigated and found out that the piping to the command won't finish sometimes. I wrote a program to check under which circumstances the piping would hang and found out that if the string is 8192 chars long (or longer) the piping would hang. Here is the program I used which just pipes to cat and uses increasing sizes for the string:
package main
import (
"io""log""math/rand""os/exec"
)
varletters= []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
funcrandSeq(nint) string {
b:=make([]rune, n)
fori:=rangeb {
b[i] =letters[rand.Intn(len(letters))]
}
returnstring(b)
}
funcmain() {
fori:=8190; i<8195; i++ {
log.Println("length: ", i)
data:=randSeq(i)
command:=exec.Command("/bin/cat")
pipe, err:=command.StdinPipe()
iferr!=nil {
log.Fatal("can not get pipe from command: ", err)
}
log.Println("writing to pipe")
_, err=io.WriteString(pipe, data)
iferr!=nil {
log.Fatal("can not write to pipe: ", err)
}
log.Println("finished writing to pipe")
pipe.Close()
_, err=command.CombinedOutput()
iferr!=nil {
log.Fatal("problem while running command: ", err)
}
}
}
I tried the same under Linux amd64 with the same go version and the program worked as expected.
The text was updated successfully, but these errors were encountered:
mikioh
changed the title
Piping to a command blocks under freebsd when input string has length >= 8192
os/exec: Piping to a command blocks under freebsd when input string has length >= 8192
Jan 5, 2015
go version go1.4 freebsd/amd64
10.0-RELEASE-p6 FreeBSD 10.0-RELEASE-p6 #0: Tue Jun 24 07:47:37 UTC 2014 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64
I investigated and found out that the piping to the command won't finish sometimes. I wrote a program to check under which circumstances the piping would hang and found out that if the string is 8192 chars long (or longer) the piping would hang. Here is the program I used which just pipes to cat and uses increasing sizes for the string:
I tried the same under Linux amd64 with the same go version and the program worked as expected.
The text was updated successfully, but these errors were encountered: