MCPcopy
hub / github.com/mongodb/node-mongodb-native / abortTransaction

Method abortTransaction

src/sessions.ts:575–670  ·  view source on GitHub ↗
(options?: { timeoutMS?: number; throwTimeout?: true })

Source from the content-addressed store, hash-verified

573 /** @internal */
574 async abortTransaction(options?: { timeoutMS?: number; throwTimeout?: true }): Promise<void>;
575 async abortTransaction(options?: { timeoutMS?: number; throwTimeout?: true }): Promise<void> {
576 if (this.transaction.state === TxnState.NO_TRANSACTION) {
577 throw new MongoTransactionError('No transaction started');
578 }
579
580 if (this.transaction.state === TxnState.STARTING_TRANSACTION) {
581 // the transaction was never started, we can safely exit here
582 this.transaction.transition(TxnState.TRANSACTION_ABORTED);
583 return;
584 }
585
586 if (this.transaction.state === TxnState.TRANSACTION_ABORTED) {
587 throw new MongoTransactionError('Cannot call abortTransaction twice');
588 }
589
590 if (
591 this.transaction.state === TxnState.TRANSACTION_COMMITTED ||
592 this.transaction.state === TxnState.TRANSACTION_COMMITTED_EMPTY
593 ) {
594 throw new MongoTransactionError(
595 'Cannot call abortTransaction after calling commitTransaction'
596 );
597 }
598
599 const command: {
600 abortTransaction: 1;
601 writeConcern?: WriteConcernOptions;
602 recoveryToken?: Document;
603 } = { abortTransaction: 1 };
604
605 const timeoutMS =
606 typeof options?.timeoutMS === 'number'
607 ? options.timeoutMS
608 : this.timeoutContext?.csotEnabled()
609 ? this.timeoutContext.timeoutMS // refresh timeoutMS for abort operation
610 : typeof this.timeoutMS === 'number'
611 ? this.timeoutMS
612 : null;
613
614 const timeoutContext =
615 timeoutMS != null
616 ? TimeoutContext.create({
617 timeoutMS,
618 serverSelectionTimeoutMS: this.clientOptions.serverSelectionTimeoutMS,
619 socketTimeoutMS: this.clientOptions.socketTimeoutMS
620 })
621 : null;
622
623 const wc = this.transaction.options.writeConcern ?? this.clientOptions?.writeConcern;
624 if (wc != null && timeoutMS == null) {
625 WriteConcern.apply(command, { wtimeoutMS: 10000, w: 'majority', ...wc });
626 }
627
628 if (this.transaction.recoveryToken) {
629 command.recoveryToken = this.transaction.recoveryToken;
630 }
631
632 const operation = new RunCommandOperation(new MongoDBNamespace('admin'), command, {

Callers 11

endSessionMethod · 0.95
withTransactionMethod · 0.95
operations.tsFile · 0.80
testFunction · 0.80
updateEmployeeInfoFunction · 0.80
updateEmployeeInfoFunction · 0.80
node_csot.test.tsFile · 0.80
updateEmployeeInfoFunction · 0.80

Calls 7

unpinMethod · 0.95
executeOperationFunction · 0.90
isRetryableWriteErrorFunction · 0.90
transitionMethod · 0.80
applyMethod · 0.80
csotEnabledMethod · 0.45

Tested by 3

testFunction · 0.64
updateEmployeeInfoFunction · 0.64
updateEmployeeInfoFunction · 0.64