photostorm / pty

PTY interface for Go
https://pkg.go.dev/github.com/creack/pty?tab=doc
MIT License
12 stars 13 forks source link

Reader never reaches EOF #3

Open Naatan opened 1 year ago

Naatan commented 1 year ago

I ran into this issue while debugging https://github.com/photostorm/pty/issues/2

When you run the test I shared there (https://github.com/ActiveState/termtest/blob/a695852f3f6479d5fbed93abd19562525c4045cf/test/pty/pty_test.go) - you'll find that it never exits, and just hangs on read.

On Linux and Mac the reader will reach EOF once the process has stopped, but on Windows this doesn't seem to happen.

photostorm commented 1 year ago

I can seen why the reader never reaches EOF. I added some code that handle that for now.

Naatan commented 12 months ago

I just tried out this most recent change, and while it does indeed exit now, it seems the resulting ProcessState of the linked process is no longer accurate. The exit code appears to always be -1.

Additionally, the change you pushed seems to ignore errors with process closing, which is a little concerning, but I also don't know the details on the rationale.

For what it's worth, this is the workaround I used:

https://github.com/ActiveState/termtest/commit/d5396a3f4815486728712813a8704877c97f63c3#diff-bd6e81b6b57a17fd2e3e07aafc51b46e56f5478e3225c19aa6567394d3df600fR38

I didn't dig into the details as this is only meant as a temporary workaround, but it appears that if I use the built-in process package it always thinks the process is running, whereas gopsutil is able to correctly infer that the process has exited.

photostorm commented 12 months ago

I just did a quick fix. I plan out how I want to handle it correctly.