Skip to content

Commit a1693ee

Browse files
committed
chore: debug retryability
1 parent fb6f806 commit a1693ee

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
@@ -523,18 +523,26 @@ export class Collection<TSchema extends Document = Document> {
523523
filter: Filter<TSchema> = {},
524524
options: Omit<FindOneOptions, ''> & Abortable = {}
525525
): Promise<WithId<TSchema> | null> {
526-
//const cursor = this.find(filter, options).limit(-1).batchSize(1);
527-
//const res = await cursor.next();
526+
const opts = { ...options };
527+
opts.singleBatch = true;
528+
if (opts.noCursorTimeout != null) {
529+
delete opts.noCursorTimeout;
530+
}
531+
if (opts.batchSize != null) {
532+
delete opts.batchSize;
533+
}
534+
const cursor = this.find(filter, opts).limit(1);
535+
return await cursor.next();
528536
//await cursor.close();
529-
return await executeOperation(
530-
this.client,
531-
new FindOneOperation(
532-
this.s.db,
533-
this.collectionName,
534-
filter,
535-
resolveOptions(this as TODO_NODE_3286, options)
536-
)
537-
);
537+
//return await executeOperation(
538+
// this.client,
539+
// new FindOneOperation(
540+
// this.s.db,
541+
// this.collectionName,
542+
// filter,
543+
// resolveOptions(this as TODO_NODE_3286, options)
544+
// )
545+
//);
538546
}
539547

540548
/**

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)