Skip to content
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

Model.bulkWrite() hangs forever when run on an empty list and ordered: false #13664

Closed
2 tasks done
JavaScriptBach opened this issue Jul 27, 2023 · 6 comments · Fixed by #13684
Closed
2 tasks done

Model.bulkWrite() hangs forever when run on an empty list and ordered: false #13664

JavaScriptBach opened this issue Jul 27, 2023 · 6 comments · Fixed by #13684
Labels
needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
Milestone

Comments

@JavaScriptBach
Copy link
Contributor

JavaScriptBach commented Jul 27, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

7.4.1

Node.js version

18.14.0

MongoDB server version

6.0.5

Typescript version (if applicable)

No response

Description

Running Model.bulkWrite([], {ordered: false}) hangs forever. This is broken on 7.4.1 and 6.11.4. It works correctly on 6.8.4.

Scanning the changelog, I suspect the issue is #13218, but I did not look too closely.

Steps to Reproduce

https://github.com/JavaScriptBach/test-mongoose-bulkwrite/tree/main

Expected Behavior

The call completes and returns.

@JonathanSun
Copy link

The reproduction link doesn't work for me, by the way (gives 404).

@JavaScriptBach
Copy link
Contributor Author

Fixed now. (I accidentally made the repo private)

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Jul 28, 2023
@IslandRhythms
Copy link
Collaborator

const mongoose = require('mongoose');

const testSchema = new mongoose.Schema({
  name: String
});

const Test = mongoose.model('Test', testSchema);

async function run() {
  await mongoose.connect('mongodb://localhost:27017');
  await mongoose.connection.dropDatabase();

  await Test.bulkWrite([], {ordered: false});
  console.log('done');
}

run();

@vkarpov15 vkarpov15 added this to the 7.4.2 milestone Aug 1, 2023
vkarpov15 added a commit that referenced this issue Aug 3, 2023
fix(model): avoid hanging on empty `bulkWrite()` with ordered: false
@JavaScriptBach
Copy link
Contributor Author

@vkarpov15 would you be willing to backport this fix onto Mongoose 6 as well? It would be very much appreciated!

@JavaScriptBach
Copy link
Contributor Author

#13701

@JavaScriptBach
Copy link
Contributor Author

@vkarpov15 thanks. 6.11.6 no longer hangs forever, but it makes Model.bulkWrite([]) throw an error, whereas before it used to just silently continue. This is arguably a backwards incompatible change depending on what the documented behavior is. Wanted to flag to you so you're aware

@vkarpov15 vkarpov15 reopened this Aug 22, 2023
@vkarpov15 vkarpov15 modified the milestones: 7.4.2, 6.12.0 Aug 22, 2023
@vkarpov15 vkarpov15 added needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue and removed confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. labels Aug 22, 2023
vkarpov15 added a commit that referenced this issue Aug 22, 2023
vkarpov15 added a commit that referenced this issue Aug 24, 2023
fix(model): make Model.bulkWrite() with empty array and ordered false not throw an error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants