Skip to content

Commit df1be41

Browse files
committed
chore: debug retryability
1 parent d1ff3c6 commit df1be41

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
@@ -554,18 +554,26 @@ export class Collection<TSchema extends Document = Document> {
554554
filter: Filter<TSchema> = {},
555555
options: Omit<FindOneOptions, ''> & Abortable = {}
556556
): Promise<WithId<TSchema> | null> {
557-
//const cursor = this.find(filter, options).limit(-1).batchSize(1);
558-
//const res = await cursor.next();
557+
const opts = { ...options };
558+
opts.singleBatch = true;
559+
if (opts.noCursorTimeout != null) {
560+
delete opts.noCursorTimeout;
561+
}
562+
if (opts.batchSize != null) {
563+
delete opts.batchSize;
564+
}
565+
const cursor = this.find(filter, opts).limit(1);
566+
return await cursor.next();
559567
//await cursor.close();
560-
return await executeOperation(
561-
this.client,
562-
new FindOneOperation(
563-
this.s.db,
564-
this.collectionName,
565-
filter,
566-
resolveOptions(this as TODO_NODE_3286, options)
567-
)
568-
);
568+
//return await executeOperation(
569+
// this.client,
570+
// new FindOneOperation(
571+
// this.s.db,
572+
// this.collectionName,
573+
// filter,
574+
// resolveOptions(this as TODO_NODE_3286, options)
575+
// )
576+
//);
569577
}
570578

571579
/**

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)