Open vergenzt opened 1 year ago
Still happening on v8 btw. The fact that its exactly 2^16
characters and hence the exact max pipe size doesn't make sense to me with the theory, but maybe I'm missing something.
The reason this is breaking is because on linux and only when stdout is the pipe, node's stream.write()
call is async.
In the case of madge, simply not calling process.exit(0)
on success would fix the issue
Seeing this also on macOS 14.7.1 with node 18.20.4 and Madge 8.0.0
If I redirect stdout from
madge
directly to a file then it works just fine. However whenever I pipemadge
's stdout to another program (in my casebcomps
, to try to find some dead code), for some reasonmadge
's output gets truncated to 65536 bytes.Example:
For thoroughness, I confirmed that the first 65535 bytes of the non-truncated result are indeed equal to the truncated result:
If I understand correctly, I believe that's equal to the size of my (MacOS) system's pipe buffer in this case:
Could this be related to https://github.com/nodejs/node/issues/22088? Given the CLI's output mechanism appears to be simply instantiating a promise without awaiting: https://github.com/pahen/madge/blob/c12ef70836855df7b9c34e5d93dfd34fdcae230d/bin/cli.js#L151
My theory: When writing directly to a file, none of the I/O promises down the chain ever have to block, so they're able to resolve to completion without Node exiting. However, once a pipe is involved, the pipe can block output until there's space on the buffer. When Node tries to write to the full pipe the write fails, and Node.js has to wait to retry. Because Node.js sees nothing on the event loop, it exits?
(That doesn't fully make sense to me because I'd think there would be something on the event loop for the retry... 🤔 Maybe it never actually retries failed writes? Not sure...)
Version info: