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

fs: do not emit open and read if stream destroyed #24055

Closed
wants to merge 9 commits into from

Conversation

dexterleng
Copy link
Contributor

@dexterleng dexterleng commented Nov 3, 2018

WIP, will write tests ASAP.

References: #23133

Addresses this:

@mcollina I don’t understand… I’m not talking about changing emit() to be a noop function or so, I’m talking about the individual call sites in our own net, tls, fs, etc. code?

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Nov 3, 2018
@mscdex mscdex added the wip Issues and PRs that are still a work in progress. label Nov 3, 2018
@Trott
Copy link
Member

Trott commented Nov 14, 2018

@nodejs/fs @mcollina

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting started with this! I think it's almost there.

lib/internal/fs/streams.js Show resolved Hide resolved
if (isOpen) {
this.once('open', closeFsStream.bind(null, this, cb, err));
// if stream is not open it will be closed in open()
if (typeof this.fd !== 'number')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are swallowing the original error here.

@mcollina mcollina added the semver-major PRs that contain breaking changes and should be released in the next major version. label Nov 26, 2018
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina mcollina requested a review from a team November 28, 2018 07:54
Copy link
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine by me
🔥🔥 alternatively we could just burn streams to the ground and start again, after this security release I'm in the mood 🔥🔥

closeFsStream(this, (er) => {
if (er) {
this.emit('error', er);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause error to be emitted after close. I think we should swallow this error.

Copy link
Contributor Author

@dexterleng dexterleng Dec 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it and the error still got emitted. The error event does not seem to come from lib/internal/fs/streams.js... 🤔

Path: parallel/test-fs-stream-no-events-after-destroy
assert.js:128
  throw err;
  ^

AssertionError [ERR_ASSERTION]: function should not have been called at /Users/hackintosh/Documents/code/node/test/parallel/test-fs-stream-no-events-after-destroy.js:15
    at ReadStream.mustNotCall (/Users/hackintosh/Documents/code/node/test/common/index.js:404:12)
    at ReadStream.emit (events.js:189:13)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at internalTickCallback (internal/process/next_tick.js:72:19)
    at process._tickCallback (internal/process/next_tick.js:47:5)
    at Function.Module.runMain (internal/modules/cjs/loader.js:778:11)
    at startup (internal/bootstrap/node.js:300:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:826:3)

@mcollina mcollina added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed wip Issues and PRs that are still a work in progress. labels Dec 21, 2018
@mcollina
Copy link
Member

@mcollina mcollina removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 21, 2018
@mcollina
Copy link
Member

There are about 2 tests failing:

test.parallel/test-fs-stream-no-events-after-destroy
test.parallel/test-fs-stream-double-close

On various environments. If they pass locally, it means they are flaky on CI: you can run a stress test locally with python tools/test.py --repeat 1024 test/parallel/test-fs-stream-no-events-after-destroy.js as an example.

While you are working on it, could you also rebase on top of master?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using "request changes" so that it does not get landed until tests are fixed.

@antsmartian
Copy link
Contributor

Ping @dexterleng 🔉

@dexterleng
Copy link
Contributor Author

Im not sure how to prevent errors from being swallowed.
I've done this:

// swallow the error to prevent error from emitting after close.

If someone else knows how to fix this please help out.

@mcollina
Copy link
Member

I don't understand what is the problem you are facing as the change looks fine to me. It seems some tests would require some changes as a result

@antsmartian
Copy link
Contributor

ping @dexterleng . Is this something you are planning to work on?

@dexterleng
Copy link
Contributor Author

@antsmartian I am no longer working on it.

@BridgeAR BridgeAR force-pushed the master branch 2 times, most recently from 8ae28ff to 2935f72 Compare May 31, 2020 12:20
@jasnell jasnell added the stalled Issues and PRs that are stalled. label Jun 25, 2020
@jasnell
Copy link
Member

jasnell commented Jul 6, 2020

Closing due to lack of continued activity

@jasnell jasnell closed this Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. semver-major PRs that contain breaking changes and should be released in the next major version. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants