Skip to content

Commit 900e9fa

Browse files
committedJan 21, 2024
fix(collection): correctly handle buffer timeouts with find()
Fix #14184
1 parent 2d68983 commit 900e9fa

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed
 

‎lib/drivers/node-mongodb-native/collection.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,23 @@ function iter(i) {
138138
let _args = args;
139139
let promise = null;
140140
let timeout = null;
141-
if (syncCollectionMethods[i]) {
142-
this.addQueue(() => {
143-
lastArg.call(this, null, this[i].apply(this, _args.slice(0, _args.length - 1)));
144-
}, []);
141+
if (syncCollectionMethods[i] && typeof lastArg === 'function') {
142+
this.addQueue(i, _args);
143+
callback = lastArg;
144+
} else if (syncCollectionMethods[i]) {
145+
promise = new this.Promise((resolve, reject) => {
146+
callback = function collectionOperationCallback(err, res) {
147+
if (timeout != null) {
148+
clearTimeout(timeout);
149+
}
150+
if (err != null) {
151+
return reject(err);
152+
}
153+
resolve(res);
154+
};
155+
_args = args.concat([callback]);
156+
this.addQueue(i, _args);
157+
});
145158
} else if (typeof lastArg === 'function') {
146159
callback = function collectionOperationCallback() {
147160
if (timeout != null) {

0 commit comments

Comments
 (0)
Please sign in to comment.