Skip to content

Commit 7941cf5

Browse files
committed
fix(NODE-3521): properly check session check
1 parent b0ca0b6 commit 7941cf5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/cursor/abstract_cursor.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,15 @@ function next<T>(cursor: AbstractCursor, blocking: boolean, callback: Callback<T
653653

654654
if (cursorId == null) {
655655
// All cursors must operate within a session, one must be made implicitly if not explicitly provided
656-
if (cursor[kSession] == null && cursor[kTopology].hasSessionSupport()) {
657-
cursor[kSession] = cursor[kTopology].startSession({ owner: cursor, explicit: false });
656+
if (cursor[kSession] == null) {
657+
if (cursor[kTopology].shouldCheckForSessionSupport()) {
658+
return cursor[kTopology].selectServer(ReadPreference.primaryPreferred, err => {
659+
if (err) return callback(err);
660+
next(cursor, blocking, callback);
661+
});
662+
} else if (cursor[kTopology].hasSessionSupport()) {
663+
cursor[kSession] = cursor[kTopology].startSession({ owner: cursor, explicit: false });
664+
}
658665
}
659666

660667
cursor._initialize(cursor[kSession], (err, state) => {

0 commit comments

Comments
 (0)