Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node process crashes if directory is deleted while it's being globbed (unhandled error event fired) #140

Closed
felixfbecker opened this issue Dec 23, 2018 · 1 comment
Assignees

Comments

@felixfbecker
Copy link

felixfbecker commented Dec 23, 2018

Environment

  • OS Version: macOS Mojave
  • Node.js Version: 11.3.0

Actual behavior

When a directory is deleted while it is being globbed with the stream API, an unhandled error event is fired that is not propagated to the returned stream, so it cannot be handled and causes the Node process to crash.

Expected behavior

Any error that happens should be propagated and emitted on the returned stream.

Steps to reproduce

  1. Create a test folder with a lot of files (e.g. a repo with lots of dependencies that are installed into node_modules. I used https://github.com/sourcegraph/lang-typescript)

  2. Run this test file:

import * as glob from 'fast-glob'
import rmfr = require('rmfr')

const dir = '/path/to/the/test/dir/node_modules'
const stream = glob.stream('**/*.*', { cwd: dir })
stream.on('error', err => {
    console.error('ERROR FIRED', err)
})
stream.on('data', match => {
    process.stdout.write('.')
})
rmfr(dir + '/node_modules')

Output:

........................................../Users/felix/git/lang-typescript/node_modules/@mrmlnc/readdir-enhanced/lib/directory-reader.js:371
        throw err;
        ^

Error: ENOENT: no such file or directory, lstat '/Users/felix/git/test/node_modules/before-after-hook/LICENSE'
Emitted 'error' event at:
    at DirectoryReader.emit (/Users/felix/git/lang-typescript/node_modules/@mrmlnc/readdir-enhanced/lib/directory-reader.js:365:14)
    at stat (/Users/felix/git/lang-typescript/node_modules/@mrmlnc/readdir-enhanced/lib/directory-reader.js:181:14)
    at call.safe (/Users/felix/git/lang-typescript/node_modules/@mrmlnc/readdir-enhanced/lib/stat.js:22:14)
    at onceWrapper (/Users/felix/git/lang-typescript/node_modules/@mrmlnc/readdir-enhanced/lib/call.js:45:17)
    at FSReqCallback.oncomplete (fs.js:161:21)

Note how ERROR FIRED is not logged, this error is an unhandled error event that crashes the process.

@mrmlnc
Copy link
Owner

mrmlnc commented Jan 7, 2019

Fixed by 2.2.5.

@mrmlnc mrmlnc closed this as completed Jan 7, 2019
@mrmlnc mrmlnc unpinned this issue Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants