Skip to content

Commit 5180e17

Browse files
committed
break up null session, and non retryable, flip if cond
1 parent 49c2b6a commit 5180e17

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/operations/execute_operation.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ async function executeOperationAsync<
142142
const readPreference = operation.readPreference ?? ReadPreference.primary;
143143
const inTransaction = !!session?.inTransaction();
144144

145-
if (!readPreference.equals(ReadPreference.primary) && inTransaction) {
145+
if (inTransaction && !readPreference.equals(ReadPreference.primary)) {
146146
throw new MongoTransactionError(
147147
`Read preference in a transaction must be primary, not: ${readPreference.mode}`
148148
);
@@ -169,8 +169,13 @@ async function executeOperationAsync<
169169

170170
const server = await topology.selectServerAsync(selector, { session });
171171

172-
if (session == null || !operation.hasAspect(Aspect.RETRYABLE)) {
173-
// No session or non-retryable operation, simple early exit
172+
if (session == null) {
173+
// No session also means it is not retryable, early exit
174+
return operation.executeAsync(server, undefined);
175+
}
176+
177+
if (!operation.hasAspect(Aspect.RETRYABLE)) {
178+
// non-retryable operation, early exit
174179
try {
175180
return await operation.executeAsync(server, session);
176181
} finally {

0 commit comments

Comments
 (0)