Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-6369

GridFS upload stream doesn't issue finish even with NodeJS driver v6.8.1

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: 7.0.0
    • Component/s: GridFS
    • 0
    • Not Needed
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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;
      

            Assignee:
            warren.james@mongodb.com Warren James
            Reporter:
            ataramina@shorecg.com Andrzej Taramina
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: