Repository navigation
Conversation
|
We recently had someone switch it to One possible alternate approach: we could come up with a better way for |
|
@jntrnr outside of busy-waiting and just checking each loop in turn, I don't believe there's support for polling multiple channels. We could pipe all command output over one channel, and wrap the buffers with some enum that distinguishes between stderr and stdout, but I think that would change too much of the interface with piping and the current ecosystem. Crates like crossbeam would allow for selecting multiple channels. How would you feel about adding a dependency? |
|
On that note, I just searched for crossbeam, and it's in my most recent Cargo.lock. It looks like nu-command uses rayon uses crossbeam, so that might make it a slightly easier call to include |
|
@fennewald - that's a thought. We have I'm also okay with your multiplexing idea of sending both stderr and stdout through the same channel and demuxing them into separate streams at the receiver end. |
|
@jntrnr I'm leaning towards crossbeam, but think it's worthwhile to try each. I'll do some rough impls and then loop back to this. Maybe in the process one will show itself to be a bad idea. |
|
making this a draft until we decide which way to go. thanks for your help figuring this out! |
|
@fennewald any updates from your end? how's the testing going? |
|
So sorry! Had gotten pulled away at work. Will follow up with updates |
b2bb417 to
75399d7
Compare
|
I'm running into difficulties testing. I can't drain both stdout and strerr simultaneously without falling into one of these undesirable situations: 1.) Spawning 1 thread for stdout, 1 for stderr, and joining afterwards At the end of the day, if we are adamant that we don't want to slurp the whole stream into memory, then we need to implement some type of polling, which means either: |
|
@jntrnr @fennewald Can we make some progress on this or should we just close it and figure out another way to approach this problem? |
|
apparently this isn't going anywhere. thanks for the submission. we'd love to find a good solution. |
Description
Fixes #5156.
External commands have their output sent over a
mpsc::sync_channelto a consumer.sync_channelhas a static maximum queue size, and calls to a full channel block.Seperately, within
crate/nu-command/src/system/complete.rs, The entire stdout output is consumed, and then the entire stderr output is consumed.The bug in #5156 arises when stderr's entire output does not fit into the stderr mpsc channel queue. The external command reads all of stdout before beginning to read stderr, but stdout will not close until the child process closes. The child process will not close until stderr can be completely written to the channel. Stderr cannot be written to the channel unless there is room in the channel's queue. The only way to have room in the channels queue is to consume the stderr stream, which loops all the way back around, and tada, deadlock.
Cheap fix is just to allow the queue to grow to arbitrary sizes. The other option to fix this is to actually create three threads, one for stdout, one for stderr, and one for joining those two, and handling exit codes. The three-thread option feels bloated and inefficient, but I understand that unbounded queue sizes is also a little scary.
Negative effects of this change is that the entirety of stderr is pushed into and out of memory, which could be problematic for large outputs.
Tests
cargo fmt --all -- --checkto check standard code formatting (cargo fmt --allapplies these changes)cargo clippy --all --all-features -- -D warnings -D clippy::unwrap_used -A clippy::needless_collectto check that you're using the standard code stylecargo build; cargo test --all --all-featuresto check that all the tests pass