Unable to safely close duplex read/write PTY FDs #49176
Unanswered
davidfiala
asked this question in
General
Replies: 1 comment 1 reply
-
As I investigated using Pro of letting FileHandle wrap an FD:
Con:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
tldr; Seems impossible to read/write a TTY FD without the risk of FD corruption race conditions.
When one has an FD to a TTY/PTY it seems the correct way to read/write is via
tty.ReadStream
andtty.WriteStream
. If your FD is readable and writeable, then you'd need both types of streams since there does not exist anything to my knowledge that makes like atty.Duplex(fd=...)
, exceptnet.Socket
which as discussed below bans TTYs.i.e,you want to read/write a TTY FD. You'll need two subclasses of net.Socket, one for reading and one for writing:
The challenge with this setup is that when you need to tear them down, such as when receiving
EIO
errno**, the library will automatically close the underlying FD. And thus you need to also destroy the other stream you've created as well because it too is no longer usable. However, that second stream is now pointing to a closed FD.(** I selected
EIO
as a common example when dealing with PTYs.)An even worse problem is that in a race condition situation you'll end up with the second stream happens to now point to a valid FD created very recently by some other code.
EBADF
errno error. Today, Node silently hides this from you.Some thoughts:
TypeError [ERR_INVALID_FD_TYPE]: Unsupported fd type: TTY
.For what it is worth: I think the larger issue here is that we may want to consider ensuring developers can manage the lifecycle of TTY FDs themselves, rather to requiring auto-closing when the Read/Write stream is ended or destroyed.
Open to any help if I've misunderstood my options -- or any ideas to move forward with the corruption risk/FD-double-close.
Beta Was this translation helpful? Give feedback.
All reactions