-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
ptmx.Read() blocks on Darwin #114
Comments
The issue is most likely in the I did manage to reproduce the random blocking behavior using this naive implementation of readUntil: const PromptChar = '\x19'
func readUntil(r io.Reader, sep, buf []byte) int {
n, err := r.Read(buf)
if err != nil {
panic(err)
}
idx := bytes.Index(buf[:n], sep)
if idx < 0 {
log.Printf("sep %q not found in %q\r\n", sep, buf[:n])
}
return idx
} A simple fix would be to use Using a pty in a daemon is usually a bad idea, it is better to use the stdlib's In a daemon, stdin would be closed, so the whole logic around SIGWINCH and Raw mode would be superfluous and should be removed. |
Closing as it is not related to the lib. Feel free to reach out if you need more help. Thank you for the sponsorship. |
When compiled with go older than 1.12 creack/pty will not include a fix for blocking Read() and will be prone to data races - but at least it will work For more information see issues: creack#88 creack#114 creack#156 creack#162
When compiled with go older than 1.12 creack/pty will not include a fix for blocking Read() and will be prone to data races - but at least it will work For more information see issues: creack#88 creack#114 creack#156 creack#162
When compiled with go older than 1.12 creack/pty will not include a fix for blocking Read() and will be prone to data races - but at least it will work For more information see issues: creack#88 creack#114 creack#156 creack#162
I'm writing a daemon that controls an instance of bash, using
creack/pty
to create the pseudoterminal, and writing commands to the pty to send them to bash and reading the output from the pty. On occasion, callingptmx.Read()
blocks the goroutine indefinitely.I expect
ptmx.Read()
to block until the program on the tty ("slave") side of the pty writes something to read. Instead it seems to block forever. To test this, I wrote a program that tries to runecho $USER
in a loop, which I have uploaded as a gist — occasionally the program runs the print on line 47 then hangs. The nondeterminism makes me suspect there's a race condition between my program andbash
, but I still expected thatptmx.Read()
would block untilbash
writes to the pty and thenptmx.Read()
would unblock.I also found that resizing my terminal (and sending sigwinch to the pty) causes the program to become unblocked. Not sure what to make of that.
Honestly I'm not sure whether this is a problem with
pty_darwin.go
or with my own code — so sorry if that's the case.Environment details, in case they're helpful:
@creack thanks for maintaining this project; it's excellent. Incidentally, let me know if you're open to doing some consulting work with pty.
The text was updated successfully, but these errors were encountered: