-
Type: Bug
-
Resolution: Gone away
-
Priority: Critical - P2
-
None
-
Affects Version/s: 7.0.0
-
Component/s: GridFS
With NodeJS driver v6.3.0 a GridFS upload stream correctly emits the "finish" event when piping from a read stream on a file.
With NodeJS driver v6.8.1 and v6.8.0, the finish even on the upload stream is never emitted, even though the code doing this is identical.
In our code fragment below, we create a promise called upload_done which will resolve when we receive the finish event on the upload stream. But the subsequent await upload_done blocks forever.
Worth noting that with the older driver we had to actually upload a file to GridFS to get it to create the files and chunks collections. However, this should still work regardless of driver version and if that was ever resolved in a later driver, though it may no longer be needed.
Here is the sample code that fails with the latest 6.8.1 NodeJS driver:
let bucket = new mongodb.GridFSBucket(db, { bucketName: LOGISTICS_GRIDFS_BUCKET_NAME }); // Get existing bucket // Delete bucket if it exists to clear out all files try { await bucket.drop(); // delete it } catch (e) {} bucket = new mongodb.GridFSBucket(db, { bucketName: LOGISTICS_GRIDFS_BUCKET_NAME }); // create new bucket // Force the bucket to create by writing a temp file then deleting it const upload_stream = bucket.openUploadStream('temp'); const upload_done = new Promise((resolve, reject) => { upload_stream .on('finish', resolve) .on('error', e => reject(new Error(`Temp file upload failed, error: ${e}`))); }); fs.createReadStream('./.empty').pipe(upload_stream); await upload_done;