-
Notifications
You must be signed in to change notification settings - Fork 1.8k
refactor(NODE-6187): refactor to use TimeoutContext abstraction #4131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
5c945e5
4149b32
8bcff1f
bcbbc45
6fe0c86
47ad495
bb5c7d0
08651b6
f8ddf6a
9936f3b
ed637ed
10dd2a1
8a770a8
926e61b
8ac2b7e
89cb002
c3b15ec
c9b217e
55a139c
db06d9f
d2c3878
e200944
2461b12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ import { | |
| } from '../sdam/server_selection'; | ||
| import type { Topology } from '../sdam/topology'; | ||
| import type { ClientSession } from '../sessions'; | ||
| import { Timeout } from '../timeout'; | ||
| import { TimeoutContext } from '../timeout'; | ||
| import { squashError, supportsRetryableWrites } from '../utils'; | ||
| import { AbstractOperation, Aspect } from './operation'; | ||
|
|
||
|
|
@@ -118,6 +118,14 @@ export async function executeOperation< | |
| ); | ||
| } | ||
|
|
||
| const timeoutContext = TimeoutContext.create({ | ||
|
||
| serverSelectionTimeoutMS: client.options.serverSelectionTimeoutMS, | ||
| waitQueueTimeoutMS: client.options.waitQueueTimeoutMS, | ||
| timeoutMS: operation.options.timeoutMS | ||
| }); | ||
|
|
||
| operation.timeoutContext = timeoutContext; | ||
|
|
||
| const readPreference = operation.readPreference ?? ReadPreference.primary; | ||
| const inTransaction = !!session?.inTransaction(); | ||
|
|
||
|
|
@@ -153,13 +161,10 @@ export async function executeOperation< | |
| selector = readPreference; | ||
| } | ||
|
|
||
| const timeout = operation.timeoutMS != null ? Timeout.expires(operation.timeoutMS) : undefined; | ||
| operation.timeout = timeout; | ||
|
|
||
| const server = await topology.selectServer(selector, { | ||
| session, | ||
| operationName: operation.commandName, | ||
| timeout | ||
| timeoutContext: operation.timeoutContext | ||
| }); | ||
|
|
||
| if (session == null) { | ||
|
|
@@ -270,9 +275,9 @@ async function retryOperation< | |
| // select a new server, and attempt to retry the operation | ||
| const server = await topology.selectServer(selector, { | ||
| session, | ||
| timeout: operation.timeout, | ||
| operationName: operation.commandName, | ||
| previousServer | ||
| previousServer, | ||
| timeoutContext: operation.timeoutContext | ||
| }); | ||
|
|
||
| if (isWriteOperation && !supportsRetryableWrites(server)) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ import { type BSONSerializeOptions, type Document, resolveBSONOptions } from '.. | |
| import { ReadPreference, type ReadPreferenceLike } from '../read_preference'; | ||
| import type { Server } from '../sdam/server'; | ||
| import type { ClientSession } from '../sessions'; | ||
| import { type Timeout } from '../timeout'; | ||
| import { type Timeout, type TimeoutContext } from '../timeout'; | ||
| import type { MongoDBNamespace } from '../utils'; | ||
|
|
||
| export const Aspect = { | ||
|
|
@@ -67,6 +67,9 @@ export abstract class AbstractOperation<TResult = any> { | |
| /** @internal */ | ||
| timeoutMS?: number; | ||
|
|
||
| /** @internal */ | ||
| timeoutContext!: TimeoutContext; | ||
|
|
||
|
||
| [kSession]: ClientSession | undefined; | ||
|
|
||
| constructor(options: OperationOptions = {}) { | ||
|
|
@@ -82,8 +85,6 @@ export abstract class AbstractOperation<TResult = any> { | |
| this.options = options; | ||
| this.bypassPinningCheck = !!options.bypassPinningCheck; | ||
| this.trySecondaryWrite = false; | ||
|
|
||
| this.timeoutMS = options.timeoutMS; | ||
| } | ||
|
|
||
| /** Must match the first key of the command object sent to the server. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -273,7 +273,7 @@ export class Server extends TypedEventEmitter<ServerEvents> { | |
| public async command( | ||
| ns: MongoDBNamespace, | ||
| command: Document, | ||
| options?: CommandOptions | ||
| options: CommandOptions | ||
|
||
| ): Promise<Document>; | ||
|
|
||
| public async command( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.