-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.2.4
-
Component/s: None
-
Environment:- Using Mongoose elsewhere in the application, but this is via GridFSBucket directly
- We are using TypeScript, although that should not have transpiled the driver
-
Empty show more show less
When using GridFs.createReadStream, the stream always emits the final 'data' event after the 'close' event, which means for libraries that stop listening when close is emitted, the last chunk is always lost.
Reproduction code:
await new Promise(resolve => { const result: string[] = []; if (!stream.readable) { resolve(result); } stream.on('data', (data) => { console.log('Got chunk'); result.push(data); }); stream.on('end', () => { console.log('Ending'); resolve(result); }); stream.on('close', () => { console.log('Closing'); resolve(result); }); });
Log
... Got chunk Got chunk Got chunk Got chunk Got chunk Got chunk Got chunk Closing Got chunk Ending
Result from db.isMaster()
{ "ismaster" : true, "maxBsonObjectSize" : 16777216, "maxMessageSizeBytes" : 48000000, "maxWriteBatchSize" : 1000, "localTime" : ISODate("2019-05-15T16:04:27.607Z"), "maxWireVersion" : 5, "minWireVersion" : 0, "readOnly" : false, "ok" : 1 }