Missing lines while stream pushing too fast
See original GitHub issueWhile the file been watching writing too fast, the read stream might miss some lines.
The fallowing code would reproduce the issue.
const fs = require('fs')
const exec = require('child_process').execSync;
const { Tail } = require('tail');
const bufferPath = __dirname + '/buffer.log';
const outputPath = __dirname + '/output.log';
exec(`echo "" > ${bufferPath}`);
exec(`echo "" > ${outputPath}`);
const tail = new Tail(bufferPath);
tail.on('line', line => fs.appendFileSync(outputPath, line + '\r\n'));
// write input file
let input = [];
for (let i = 0; i < 100; i++) {
input.push(`${i}: {a:1,b:2}\r\n`)
}
input.forEach((msg) => fs.appendFile(bufferPath, msg, () => {}))
As we can see the output.log
had less than 100 lines. Bigger number we set to for-loop, more lines would been missed.
This might cause Node.js streaming usage problem, we might should use pipeline instead of on('data', cb)
Backpressuring in Streams - https://nodejs.org/en/docs/guides/backpressuring-in-streams/
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
How to Stop Buffering When Streaming | SatelliteInternet.com
5 quick fixes for buffering while streaming · Lower the video quality to standard definition (SD). · Disconnect all other devices in the...
Read more >CPR Online Portion Study Guide 2021 January - Quizlet
During CPR on a child, interruptions to chest compressions should be limited to no ... as team leader you notice that your compressor...
Read more >Central lines: Recognizing, preventing, and troubleshooting ...
This article discusses potential complications—catheter occlusion, bleeding and hematoma, catheter-tip migration, catheter rupture, phlebitis ...
Read more >Node.js Streams: Everything you need to know - freeCodeCamp
When a client asks for that big file, we stream it one chunk at a time, which means we don't buffer it in...
Read more >Home pregnancy tests: Your most pressing questions, answered
Five seconds feels a bit longer when aiming your pee, but pulling the stick away too quickly or not leaving it in your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nicolas-goudry You are amazing, man! I will try it later.
Although I tested on multiple OSes I can’t replicate the issue. Closing it.