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

GridFSBucketWriteStream doesn't implement stream.Writable properly

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.4
    • Affects Version/s: Not Applicable
    • Component/s: None

      From the node stream docs:

      Custom Writable streams must call the new stream.Writable([options]) constructor and implement the writable._write() and/or writable._writev() method.
      

      GridFSBucketWriteStream does not call the stream.Writable constructor. Because node v13 changed the implementation of stream.Writable.destroy(), calling .destroy() on a GridFSBucketWriteStream throws an error of "TypeError: Cannot read property 'destroyed' of undefined". This happens, because stream.Writable._writableState is set in the stream.Writable constructor, but is not set in GridFSBucketWriteStream. .destroy() tries to access ._writableState.destroyed.

      Even though .destroy() probably didn't do anything when called for GridFSBucketWriteStream, it's non-failing implementation allows the use of pump / stream.pipeline, which calls .destroy when available.

      pump is used by multer-gridfs-storage (used to stream files into gridfs in express apps), which now fails with node v13 under certain conditions.

      It is suggested that the GridFS streams properly inherit from the corresponding node streams. The current use of util.inherits is discouraged in the node docs as well:

      Usage of util.inherits() is discouraged. Please use the ES6 class and extends keywords to get language level inheritance support. 
      

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            wolfgang.walther86@googlemail.com Wolfgang Walther
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: