Skip to content

Commit ec2feee

Browse files
committed
fix: state checks
1 parent ef231ee commit ec2feee

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/cmap/connection.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,11 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
493493
private async *sendCommand(
494494
ns: MongoDBNamespace,
495495
command: Document,
496-
options: CommandOptions,
496+
options: CommandOptions & Abortable,
497497
responseType?: MongoDBResponseConstructor
498498
) {
499+
options?.signal?.throwIfAborted();
500+
499501
const message = this.prepareCommand(ns.db, command, options);
500502
let started = 0;
501503
if (this.shouldEmitAndLogCommand) {
@@ -611,10 +613,12 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
611613
public async command(
612614
ns: MongoDBNamespace,
613615
command: Document,
614-
options: CommandOptions = {},
616+
options: CommandOptions & Abortable = {},
615617
responseType?: MongoDBResponseConstructor
616618
): Promise<Document> {
617619
this.throwIfAborted();
620+
options.signal?.throwIfAborted();
621+
618622
for await (const document of this.sendCommand(ns, command, options, responseType)) {
619623
if (options.timeoutContext?.csotEnabled()) {
620624
if (MongoDBResponse.is(document)) {

src/operations/execute_operation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ export async function executeOperation<
6464
throw new MongoRuntimeError('This method requires a valid operation instance');
6565
}
6666

67-
// Like CSOT, an operation signal interruption does not relate to auto-connect
68-
const topology = await abortable(autoConnect(client), operation.options);
67+
const topology =
68+
client.topology == null
69+
? await abortable(autoConnect(client), operation.options)
70+
: client.topology;
6971

7072
// The driver sessions spec mandates that we implicitly create sessions for operations
7173
// that are not explicitly provided with a session.

0 commit comments

Comments
 (0)