No more pipes to file descriptors
Opened this issue · 3 comments
According to libuv/libuv#2658, pipes to file descriptors are fraught with problems. This is part of what's causing #1083 and #1023
Luvit currently creates pipes to fd
when stdout/stdin come from files:
Lines 322 to 352 in d841d16
This should be avoided in favor of something else. Need to look into how other projects handle this (node, etc).
More related issues:
As far as I can tell, this is where Node sets up stdout/stdin/stderr streams
For writable (stdout/stderr), it uses either tty
, pipe
, or a synchronous fs
write stream. For readable (stdin), it uses either tty
, pipe
, or an async fs
read stream.
So Luvit is just handling the file
handle type incorrectly.
This change is a little bit more complicated than it first appears, because Luvit expects stdout
/stdin
to always be a raw uv_stream_t
userdata (uv_tty_t
or uv_pipe_t
) throughout its deps. So, simply making stdout
a fs.WriteStreamSync
instead leads to various problems wherever stdout
is used (and same with stdin
being a fs.ReadStream
).
As far as I can tell, we have a few options here:
- Do like Node does and always wrap
stdout
/stdin
/stderr
in Stream wrappers (Writable
/Readable
). This would be very non-backwards-compatible (since, right now,uv.write(stdout, ...)
is expected to work, but it wouldn't work once everything is converted to a wrapper), but it's probably the best long-term solution. - Only use the Stream wrappers for
file
handles and then make all usages ofstdout
/stdin
in Luvit work for either one (i.e. convertuv.write(stdout, ...)
tostdout:write(...)
which would work on both types). This would still not be backwards-compatible forfile
handle types, butpipe
andtty
types would be unaffected. - Keep using
uv_pipe_t
to a file for stdout/stdinfile
handles, and then try to fix any problems that come from it (like not callinguv.shutdown
on them when they arefile
handles). This would be the most backwards-compatible option but it's definitely not a good long-term strategy. Could maybe be used as a quick band-aid approach to getfile
stdout/stdin to stop aborting, though.
Maybe it's time to start considering luvit 3.0.