Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/gridfs/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ export class GridFSBucketWriteStream extends Writable {
const remainingTimeMS = this.timeoutContext?.getRemainingTimeMSOrThrow(
`Upload timed out after ${this.timeoutContext?.timeoutMS}ms`
);
await this.chunks.deleteMany({ files_id: this.id, timeoutMS: remainingTimeMS });

await this.chunks.deleteMany({ files_id: this.id }, { timeoutMS: remainingTimeMS });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,6 @@ describe('CSOT spec prose tests', function () {
);
expect(maybeError).to.be.instanceof(MongoOperationTimeoutError);
});

it('Aborting an upload stream can be timed out', metadata, async function () {
/**
* This test only applies to drivers that provide an API to abort a GridFS upload stream.
Expand Down Expand Up @@ -739,33 +738,33 @@ describe('CSOT spec prose tests', function () {
data: {
failCommands: ['delete'],
blockConnection: true,
blockTimeMS: 200
blockTimeMS: 300
}
};

await internalClient.db().admin().command(failpoint);
const bucket = new GridFSBucket(client.db('db'), { chunkSizeBytes: 2 });
// 2. Call `bucket.open_upload_stream()` with the filename `filename` to create an upload stream (referred to as `uploadStream`).
// - Expect this to succeed and return a non-null stream.
const uploadStream = bucket.openUploadStream('filename', { timeoutMS: 300 });
const { duration } = await measureDuration(async () => {
// 3. Using `uploadStream`, upload the bytes `[0x01, 0x02, 0x03, 0x04]`.

const data = Buffer.from('01020304', 'hex');
await pipeline(Readable.from(Buffer.from('01020304', 'hex')), uploadStream, {
end: false
});

const { promise: writePromise, resolve, reject } = promiseWithResolvers<void>();
uploadStream.on('error', error => uploadStream.destroy(error));
uploadStream.write(data, error => {
if (error) reject(error);
else resolve();
// 4. Call `uploadStream.abort()`.
// - Expect this to fail with a timeout error.
const timeoutError = await uploadStream.abort().then(
() => null,
error => error
);
expect(timeoutError).to.be.instanceOf(MongoOperationTimeoutError);
});
let maybeError = await writePromise.then(
() => null,
e => e
);
expect(maybeError).to.be.null;

maybeError = await uploadStream.abort().then(
() => null,
error => error
);
expect(maybeError).to.be.instanceOf(MongoOperationTimeoutError);
expect(duration).to.be.within(300 - 15, 300 + 15);

uploadStream.destroy();
});
});
Expand Down