Multer: Race condition in test

Created on 3 Oct 2015  Β·  8Comments  Β·  Source: expressjs/multer

This seems to be very very rare, found it on Travis today.

$ npm test

> [email protected] test /home/travis/build/expressjs/multer
> standard && mocha



  Disk Storage
    βœ“ should process parser/form-data POST request
    1) should process empty fields and an empty file
    βœ“ should process multiple files
    βœ“ should remove uploaded files on error
    βœ“ should report error when directory doesn't exist

  Error Handling
    βœ“ should respect parts limit
    βœ“ should respect file size limit
    βœ“ should respect file count limit
    βœ“ should respect file key limit
    βœ“ should respect field key limit
    βœ“ should respect field value limit
    βœ“ should respect field count limit
    βœ“ should respect fields given
    βœ“ should report errors from storage engines
    βœ“ should report errors from busboy constructor
    βœ“ should report errors from busboy parsing

  Expected files
    βœ“ should reject single unexpected file
    βœ“ should reject array of multiple files
    βœ“ should reject overflowing arrays
    βœ“ should accept files with expected fieldname
    βœ“ should reject files with unexpected fieldname

  Express Integration
    βœ“ should work with express error handling (42ms)
    βœ“ should work when receiving error from fileFilter

  Fields
    βœ“ should process multiple fields
    βœ“ should process empty fields
    βœ“ should not process non-multipart POST request
    βœ“ should not process non-multipart GET request
    βœ“ should handle basic keys
    βœ“ should handle multiple values
    βœ“ should handle deeper structure
    βœ“ should handle sparse arrays
    βœ“ should handle even deeper
    βœ“ should handle such deep
    βœ“ should handle merge behaviour
    βœ“ should handle bad fields
    βœ“ should convert arrays into objects

  File Filter
    βœ“ should skip some files
    βœ“ should report errors from fileFilter

  File ordering
    βœ“ should present files in same order as they came

  Functionality
    βœ“ should upload the file to the `dest` dir
    βœ“ should rename the uploaded file
    βœ“ should ensure all req.files values (single-file per field) point to an array
    βœ“ should ensure all req.files values (multi-files per field) point to an array
    βœ“ should rename the destination directory to a different directory

  Issue #232
    βœ“ should report limit errors

  Memory Storage
    βœ“ should process multipart/form-data POST request
    βœ“ should process empty fields and an empty file
    βœ“ should process multiple files

  Reuse Middleware
    βœ“ should accept multiple requests (48ms)

  Select Field
    βœ“ should select the first file with fieldname
    βœ“ should select all files with fieldname

  Unicode
    βœ“ should handle unicode filenames


  51 passing (412ms)
  1 failing

  1) Disk Storage should process empty fields and an empty file:
     Uncaught Error: ENOENT: no such file or directory, stat '/tmp/gvQUuo2Ne54/154080e1a19a860bba7db8c648f4358f'
      at Error (native)
      at Object.fs.statSync (fs.js:849:18)
      at Object.fileSize (test/_util.js:11:13)
      at test/disk-storage.js:81:25
      at Immediate.<anonymous> (test/_util.js:32:37)



npm ERR! Test failed.  See above for more details.

The command "npm test" exited with 1.

Done. Your build exited with 1.

Most helpful comment

The referenced fix in Node core has landed, this should be tested again and determined if it's fixed for multer.

I haven't noticed the CITGM failure mentioned in https://github.com/expressjs/multer/issues/238#issuecomment-540915547 in a long time so I'd guess that any Node.js part of this is fixed on the master branch at least.

All 8 comments

@LinusU - are we seeing this still? (just trying to figure out whether we should keep it opened or not)

@LinusU - are we seeing this still? (just trying to figure out whether we should keep it opened or not)

@gireeshpunathil Definitely still seeing it. I've noticed it a fair amount in Node.js's ecosystem-testing utility CITGM. For example: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/2040/nodes=ubuntu1604-64/testReport/junit/(root)/citgm/multer_v1_4_2/

I also just reproduced it locally on macOS Mojave by adding mocha's .only() to the relevant test. In other words, I changed:
https://github.com/expressjs/multer/blob/59376904cf2317b3683368c8cbe3736356ffacd2/test/disk-storage.js#L51

...to be:

  it.only('should process empty fields and an empty file', function (done) {

...and then ran

$ while true; do
> node node_modules/.bin/mocha
>   if [[ "$?" -ne 0 ]]; then 
> break
> fi
> done

...and the failure seems to come up every twenty or thirty runs or so:

  1) Disk Storage should process empty fields and an empty file:
     Uncaught Error: ENOENT: no such file or directory, stat '/var/folders/7w/pzd4440x60d3gkc3cv7rj8lc0000gp/T/2MR49F8/a25a4ece9ac48e4fc21b525cd7edadd2'
      at Object.statSync (fs.js:926:3)
      at Object.fileSize (test/_util.js:11:13)
      at test/disk-storage.js:80:25
      at Immediate.<anonymous> (test/_util.js:32:37)
      at processImmediate (internal/timers.js:441:21)

Changing:

https://github.com/expressjs/multer/blob/59376904cf2317b3683368c8cbe3736356ffacd2/storage/disk.js#L42

...to:

      outStream.on('close', function () {

...makes it so I can't reproduce the test failure anymore.

Probably bug in Node. Proposed PR in core https://github.com/nodejs/node/pull/29930.

The referenced fix in Node core has landed, this should be tested again and determined if it's fixed for multer.

The referenced fix in Node core has landed, this should be tested again and determined if it's fixed for multer.

I haven't noticed the CITGM failure mentioned in https://github.com/expressjs/multer/issues/238#issuecomment-540915547 in a long time so I'd guess that any Node.js part of this is fixed on the master branch at least.

so closing as resolved; we can always re-open if necessary.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Gabxi picture Gabxi  Β·  3Comments

josephstgh picture josephstgh  Β·  3Comments

sant123 picture sant123  Β·  4Comments

tjabdoullah picture tjabdoullah  Β·  4Comments

ChristianRich picture ChristianRich  Β·  4Comments