Exception on GridFSBucket upload stream

26 views
Skip to first unread message

Andris Reinman

unread,
May 25, 2017, 3:59:03 AM5/25/17
to node-mongodb-native
I have a relatively simple code to upload files to GridFS with mon...@2.2.27 (Node.js v6.10.3):

```
let store = gridstore.openUploadStreamWithId(id, null, opts);
store.once('error', err => {
    callback(err);
});
store.once('finish', () => {
    callback(null, id);
});
store.end(data);
```

At least once there has been an exception while uploading. Unfortunately I don't have the data available that was trying to get uploaded. The exception that was thrown looks like this:

```
/path/to/app/node_modules/mongodb/lib/utils.js:123
    process.nextTick(function() { throw err; });
                                   ^
Error: Digest already called
    at Error (native)
    at Hash.digest (crypto.js:81:23)
    at checkDone (/path/to/app/node_modules/mongodb/lib/gridfs-stream/upload.js:259:17)
    at /path/to/app/node_modules/mongodb/lib/gridfs-stream/upload.js:427:11
    at /path/to/app/node_modules/mongodb/lib/collection.js:536:5
    at /path/to/app/node_modules/mongodb/lib/collection.js:714:5
    at handleCallback (/path/to/app/node_modules/mongodb/lib/utils.js:120:56)
    at executeCommands (/path/to/app/node_modules/mongodb/lib/bulk/ordered.js:398:12)
    at resultHandler (/path/to/app/node_modules/mongodb/lib/bulk/ordered.js:425:5)
    at /path/to/app/node_modules/mongodb-core/lib/connection/pool.js:469:18
```

The app has uploaded more than a million files and I've seen this exception only once so far. It caused the process to crash though as it is uncatchable (in normal ways).

Regards,
Andris Reinman

christkv

unread,
May 25, 2017, 7:26:40 AM5/25/17
to node-mongodb-native
I suspect there was a race condition where checkDone is called twice (thus calling digest on the md5 hash twice). I added a ticket and fix that should be out in 2.2.28

Reply all
Reply to author
Forward
0 new messages