Skip to content

Commit

Permalink
fix(collection): correctly handle buffer timeouts with find()
Browse files Browse the repository at this point in the history
Fix #14184
  • Loading branch information
vkarpov15 committed Jan 21, 2024
1 parent 2d68983 commit 900e9fa
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/drivers/node-mongodb-native/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,23 @@ function iter(i) {
let _args = args;
let promise = null;
let timeout = null;
if (syncCollectionMethods[i]) {
this.addQueue(() => {
lastArg.call(this, null, this[i].apply(this, _args.slice(0, _args.length - 1)));
}, []);
if (syncCollectionMethods[i] && typeof lastArg === 'function') {
this.addQueue(i, _args);
callback = lastArg;
} else if (syncCollectionMethods[i]) {
promise = new this.Promise((resolve, reject) => {
callback = function collectionOperationCallback(err, res) {
if (timeout != null) {
clearTimeout(timeout);
}
if (err != null) {
return reject(err);
}
resolve(res);
};
_args = args.concat([callback]);
this.addQueue(i, _args);
});
} else if (typeof lastArg === 'function') {
callback = function collectionOperationCallback() {
if (timeout != null) {
Expand Down

0 comments on commit 900e9fa

Please sign in to comment.