question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing lines while stream pushing too fast

See original GitHub issue

While 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.

image

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:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JasinYipcommented, Dec 14, 2020

@nicolas-goudry You are amazing, man! I will try it later.

0reactions
lucagrullacommented, Jan 2, 2021

Although I tested on multiple OSes I can’t replicate the issue. Closing it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found