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.

Stream stuck when used with mongodb and node10

See original GitHub issue

Hello, I really like Highland and I would like to continue to use it but it starts to be a problem with newest version of node.

The following example works just fine with node 8/9 but stays stuck when using node 10+

const MongoClient = require('mongodb').MongoClient;
const hl = require('highland');

const MONGO_URL = 'mongodb://localhost:27017/';

const DB_NAME = 'someDb';
const COLLECTION = 'someCollection';

const run = async () => {
  const mongo = new MongoClient(url);

  await mongo.connect();
  const cursor = mongo.db(DB_NAME)
    .collection(COLLECTION)
    .find()
    .stream();

  return new Promise((resolve, reject) => {
    return hl(cursor)
    .batch(5)
    .flatten()
    .map(x => console.log(x && x._id))
    .stopOnError(reject)
    .done(resolve);
  });
};

run()
  .catch(console.log)
  .then(() => process.exit())

If you replace the mongoDb stream by a simple stream like this one it works just fine:

class Counter extends Readable {
  constructor(opt) {
    super({ ...opt, objectMode: true });
    this._max = 1000000;
    this._index = 1;
  }

  _read() {
    const i = this._index++;
    if (i > this._max)
      this.push(null);
    else {
      this.push({ count: i });
    }
  }
}

Thing is I had a look at the stream implementation inside mongoDB lib and they used the node stream implementation, I have seen nothing weird about it. And something else is a little bit strange, if you remove the flatten inside the hl chain, the stream will not be stucked anymore(even with node10).

Anyway I have no clue what the problem is so if anyone has an idea please share it.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
vqvucommented, Feb 15, 2019

This fix has been released as 3.0.0-beta.8 and 2.13.1.

1reaction
jeanbaptiste-brasseletcommented, Feb 14, 2019

Hello,

I can confirm the changes also fix my use case 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change events stream stops working when a node fails in ...
I am having a problem with mongodb (version 4.2), ... Starting MongoDB 3.6 change streams are using read concern “majority” by default which ......
Read more >
Change stream hanging while fetching update events - M220J
So i was working on ChangeStreams test case in the mongo mflix , incase ... UPDATE_LOOKUP) to db.watch(oddFilter) then the test case hangs...
Read more >
Kafka connector stuck with MongoDB Change Stream error
Hello Team, We encountered following error when were doing Kafka MongoDB Source Connector: [2021-03-02 07:15:33282] INFO An exception ...
Read more >
Read change streams with multiple threads - MongoDB
You can have multiple thread receiving different change stream message if the query used to set up the stream is different.
Read more >
Change Streams & Triggers with Node.js Tutorial - MongoDB
Discover how to react to changes in your MongoDB database using change streams implemented in Node.js and Atlas triggers.
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