Skip to content

ptmx.Read() blocks on Darwin #114

@noahlt

Description

@noahlt

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, calling ptmx.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 run echo $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 and bash, but I still expected that ptmx.Read() would block until bash writes to the pty and then ptmx.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:

  • macOS 10.14.6
  • golang 1.16
  • creack/pty v1.1.11

@creack thanks for maintaining this project; it's excellent. Incidentally, let me know if you're open to doing some consulting work with pty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions