I found I had a problem writing from a LineWriter to a Fifo pipe being consumed by another process. Buffering on the LineWriter greater than the pipe capacity caused dropped data--even when doing a flush after each write.
Lowering the buffer size to < the pipe size fixed it...as well as just using a File to write.
Is there a potential bug in LineWriter with regard to flush?
sigmaSd
December 10, 2021, 8:21pm
2
I asked the same thing xD
I expect the problem is that the buffer it uses for stdout is filled up and never consumed, so it hangs while waiting for the buffer to be read. In the example you can just use Command::output instead, but I assume your actual use case is more complex.
Try this for example
let mut stdout = cmd.stdout.take().unwrap();
let mut buf = [0; 512];
while cmd.try_wait().unwrap().is_none() {
stdout.read(&mut buf).unwrap();
}
edit: There's an open issue regarding this, where you …
sigmaSd
December 10, 2021, 8:23pm
3
Hmm maybe its not exactly similar, but itcould be related
sigmaSd
December 10, 2021, 8:34pm
4
So basicly my understanding is:
you cant write more than pipe size at once
The solution is to write less then pipe size and to make sure the receving process continuly read from the pipe inorder to clear it for the next write
Basically -- The solution is to write less then pipe size. The consuming on the other end is just normal Linux operations assumed.
sigmaSd
December 10, 2021, 8:43pm
6
But you mentioned data drop ,not blocking when excceding pipe size, I would speculate that the consumer is overwriting the data somehow
system
Closed
March 10, 2022, 8:43pm
7
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.