Skip to content

Commit 07ab153

Browse files
committed
chore: debug retryability
1 parent f8767d1 commit 07ab153

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

src/collection.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -551,18 +551,26 @@ export class Collection<TSchema extends Document = Document> {
551551
filter: Filter<TSchema> = {},
552552
options: Omit<FindOneOptions, ''> & Abortable = {}
553553
): Promise<WithId<TSchema> | null> {
554-
//const cursor = this.find(filter, options).limit(-1).batchSize(1);
555-
//const res = await cursor.next();
554+
const opts = { ...options };
555+
opts.singleBatch = true;
556+
if (opts.noCursorTimeout != null) {
557+
delete opts.noCursorTimeout;
558+
}
559+
if (opts.batchSize != null) {
560+
delete opts.batchSize;
561+
}
562+
const cursor = this.find(filter, opts).limit(1);
563+
return await cursor.next();
556564
//await cursor.close();
557-
return await executeOperation(
558-
this.client,
559-
new FindOneOperation(
560-
this.s.db,
561-
this.collectionName,
562-
filter,
563-
resolveOptions(this as TODO_NODE_3286, options)
564-
)
565-
);
565+
//return await executeOperation(
566+
// this.client,
567+
// new FindOneOperation(
568+
// this.s.db,
569+
// this.collectionName,
570+
// filter,
571+
// resolveOptions(this as TODO_NODE_3286, options)
572+
// )
573+
//);
566574
}
567575

568576
/**

src/operations/execute_operation.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ async function tryOperation<
232232
let previousServer: ServerDescription | undefined;
233233

234234
for (let tries = 0; tries < maxTries; tries++) {
235+
console.log('trying', tries, maxTries, willRetry, operation.commandName);
235236
if (previousOperationError) {
236237
if (hasWriteAspect && previousOperationError.code === MMAPv1_RETRY_WRITES_ERROR_CODE) {
237238
throw new MongoServerError({
@@ -248,8 +249,10 @@ async function tryOperation<
248249
if (hasWriteAspect && !isRetryableWriteError(previousOperationError))
249250
throw previousOperationError;
250251

251-
if (hasReadAspect && !isRetryableReadError(previousOperationError))
252+
if (hasReadAspect && !isRetryableReadError(previousOperationError)) {
253+
console.log(previousOperationError, isRetryableReadError(previousOperationError));
252254
throw previousOperationError;
255+
}
253256

254257
if (
255258
previousOperationError instanceof MongoNetworkError &&
@@ -280,8 +283,10 @@ async function tryOperation<
280283
if (tries > 0 && operation.hasAspect(Aspect.COMMAND_BATCHING)) {
281284
operation.resetBatch();
282285
}
286+
console.log('executing', operation.commandName);
283287
return await operation.execute(server, session, timeoutContext);
284288
} catch (operationError) {
289+
console.log('operationError', operationError);
285290
if (!(operationError instanceof MongoError)) throw operationError;
286291
if (
287292
previousOperationError != null &&

test/integration/retryable-reads/retryable_reads.spec.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const UNIMPLEMENTED_APIS = [
1414

1515
const skippedTests = ['collection.listIndexes succeeds after retryable handshake network error'];
1616

17-
describe('Retryable Reads (unified)', function () {
17+
describe.only('Retryable Reads (unified)', function () {
1818
runUnifiedSuite(loadSpecTests(path.join('retryable-reads', 'unified')), ({ description }) => {
1919
for (const apiName of UNIMPLEMENTED_APIS) {
2020
if (description.toLowerCase().includes(apiName.toLowerCase())) {

0 commit comments

Comments
 (0)