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

Uncaught stream error: The reader is already destroyed #282

Closed
MarcusCemes opened this issue Jul 18, 2020 · 2 comments
Closed

Uncaught stream error: The reader is already destroyed #282

MarcusCemes opened this issue Jul 18, 2020 · 2 comments
Assignees
Milestone

Comments

@MarcusCemes
Copy link

MarcusCemes commented Jul 18, 2020

Environment

  • OS Version: Ubuntu, Windows, CodeSandbox container
  • Node.js Version: 14

Actual behavior

  1. A filesystem error (such as EACCES) is encountered
  2. The readable stream will emit an error event
  3. Node.js will log an uncaught error, or crash immediately on Windows

Expected behavior

  1. The stream emits an error event
    a. The stream ends
    b. The stream keeps emitting data/errors

Suppressing error is an option, it's not ideal. I will resort to buffering all results via the async API for now.

Steps to reproduce

The following command is bound to hit some permission issues somewhere under the root filesystem:

require("fast-glob").stream("/**/*")
    .on("error", () => console.error("!s"))
    .pipe(new stream.PassThrough())
    .on("error", () => console.error("!p"));

It will output the following:

!s
Uncaught Error: The reader is already destroyed
    at AsyncReader.destroy (/.../packages/cli/node_modules/@nodelib/fs.walk/out/readers/async.js:33:19)
    at Readable.destroy (internal/streams/destroy.js:36:8)
    at Readable.<anonymous> (/.../node_modules/fast-glob/out/providers/stream.js:21:41)
    at Object.onceWrapper (events.js:421:28)
    at Readable.emit (events.js:315:20)
    at Readable.EventEmitter.emit (domain.js:547:15)
    at /.../node_modules/fast-glob/out/utils/stream.js:16:40
    at Array.forEach (<anonymous>)
    at propagateCloseEventToSources (/.../node_modules/fast-glob/out/utils/stream.js:16:13)

Code sample

Here's a working reproduction:

Edit fast-glob stream error handling

Edit: you may need to fork the sandbox and restart the container

@MarcusCemes
Copy link
Author

Perhaps related, with the async API, something is still throwing uncaught errors when hitting filesystem permission issues.
However, this occurs on Windows only, it is probably due to a system call, and possibly the new efficient "modern mode"?.
Ubuntu catches the promise correctly. The above issue (stream error) is platform agnostic.

Example with protected OS folder in the REPL:

> require("fast-glob")("D:/**/*").catch(() => {});
Promise { <pending> }

Uncaught [Error: EPERM: operation not permitted, scandir 'D:\WindowsApps'] {
  errno: -4048,
  code: 'EPERM',
  syscall: 'scandir',
  path: 'D:\\WindowsApps',
  domainEmitter: EventEmitter {
    _events: [Object: null prototype] {
      entry: [Function (anonymous)],
      end: [Function]
    },
    _eventsCount: 2,
    _maxListeners: undefined,
    [Symbol(kCapture)]: false
  },
  domainThrown: false
}

Granted, nobody is going to be globbing Windows folders, but read permission errors are not uncommon.

@mrmlnc
Copy link
Owner

mrmlnc commented Dec 28, 2020

Works with a fresh install of the fast-glob package.

@mrmlnc mrmlnc closed this as completed Dec 28, 2020
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