-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deadlock when using batch
with flatMap
and mongo stream as source (node >= 10)
#693
Comments
Created a small github repo with Travis on it with a similar test case: Setup Travis to build it daily, so the above image should go green once its fixed. |
interestingly if you use the hl(mongoStream)
.ratelimit(110, 0)
.batch(300) it will actually finish, while if I put 120 for the amount it will hang. |
what I've found sofar: I'm tempted to give up at this point and just start on a big project of replacing all highland usages with some other solutions. :( |
I took a quick look at your test repo and saw you are using highland 3 which if I recall, is missing some work around when resources are destroyed which may be affecting this. What happens if you use the stable Highland 2.13.5? https://www.npmjs.com/package/highland Also what happens if you use Lastly, looking at the source: https://github.com/caolan/highland/blob/3.0.0/lib/index.js#L2785-L2792 It has a clause to close the stream when the source stream closes. That suggests it may be the mongo node stream that is not triggering the completion because it's also batching and will not close until it's satisfied. Could you try adding an event listener to the mongo stream to see if it dispatches a |
Hmm with version 2.13.5 it finishes nicely without the issue. That is cool, now just need to see why did we started to use 3. :D In regards to the edit: I use |
Ok that's at least progress. I see your updated test repo and the use of toPromise. You're right that Also, based on how you're using batch and flatMap here, would |
Indeed progress, thank you for the support :) For when the test runs on the non-batched stream it triggers all three event handlers, but on the second run with batched stream, none of them gets triggered. How would the |
Thanks for that info! I'm going to dig in today and see if I can pinpoint if it's a highland issue specifically or something with the batched mongo stream. As for |
Made some progress. async function main () {
const client = await MongoClient.connect(url, opts);
const db = client.db("test");
const col = db.collection("test");
await col.removeMany();
await col.insertMany(docs);
// This function will explode in six seconds
timeout(6000)
.done(() => {
throw new Error("APPLICATION TIMED OUT");
client.close();
process.exit(1);
});
return _.of(col)
.flatMap(fetchDocs)
.batch(11)
.consume(logStream)
.flatMap(_)
.reduce(append, [])
.toCallback((err, xs) => {
client.close();
if (err) {
console.error(err);
process.exit(1);
}
assert.deepEqual(xs, docs, `DOCS WERE NOT RETUREND. INSTEAD FOUND "${xs}"`);
console.log("Completed!", xs);
process.exit(0);
});
} That works, the main difference being My next step is to create a new Node Readable stream that kinda simulates the cursor.stream. That should confirm whether this is a Highland or Mongo DB API issue. My progress is at https://github.com/eccentric-j/highland-batch-repro which includes a docker-compose file to make it easier to run. |
wow interesting, tried to use const mongoStream = hl.of(collection.find().stream()).flatMap(hl); instead of the const mongoStream = collection.find().stream(); in my tests and indeed the streaming works if wrapped like this. |
Tried This has me leaning towards the issue residing in mongodb's |
has anyone managed to make any further progress on this? |
@adrian-gierakowski unfortunately no, personally I started to move away from using highland utilizing |
The following test deadlocks (
toCallback
never gets called):You save save the above in
tests/batch_deadlock.js
, install mongo drives withnpm i mongodb
and finally run it withnpx nodeunit tests/batch_deadlock.js
. It should deadlock when running with node version >= 10, but passes when ran with node 8.x.I've also left a few comments in the code which show some tweaks that make the deadlock go away.
The text was updated successfully, but these errors were encountered: