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

worker: do not throw on property access or postMessage after termination #25871

Closed
wants to merge 2 commits into from

Conversation

chjj
Copy link
Contributor

@chjj chjj commented Feb 1, 2019

Worker#postMessage, Worker#stdin, Worker#stdout, and Worker#stderr currently throw if called/accessed after a worker is terminated.

postMessage silently fails in the browser after termination. It also seems cleaner if the stdio streams are set to null after termination. This PR implements that behavior.

@nodejs-github-bot nodejs-github-bot added the worker Issues and PRs related to Worker support. label Feb 1, 2019
@addaleax
Copy link
Member

addaleax commented Feb 1, 2019

CI: https://ci.nodejs.org/job/node-test-pull-request/20512/

/cc @nodejs/workers

@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 1, 2019
@sam-github
Copy link
Contributor

sam-github commented Feb 1, 2019

It also seems cleaner if the stdio streams are set to null after termination.

I don't know, it seems better to me if they continue to exist, but are closed. null will make property access start to throw, which is what is happening now, except the error will be more mysterious.

EDIT: sorry, ignore this. I thought this was the cluster Worker, but its not. I have no opinion on WebWorkers. The API is supposed to be standardized, does the standard not address this?

@addaleax addaleax removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 1, 2019
@sam-github
Copy link
Contributor

I edited my comment above, but then remembered edits don't cause notifications. See ----^

@chjj
Copy link
Contributor Author

chjj commented Feb 1, 2019

@sam-github, I'm not sure what the standard says, but chromium 71 fails silently when calling Worker#postMessage after termination (the same is true of MessagePort instances).

stdin, stdout, and stderr are specific to node so I guess it's up to us to do what we want with them. I feel like it's bad practice to have getters which throw.

@chjj
Copy link
Contributor Author

chjj commented Feb 1, 2019

Mmm, will modify to make the linter happy.

@chjj
Copy link
Contributor Author

chjj commented Feb 1, 2019

Should be fixed. I can squash and push again if that's preferred.


// Sanity check.
assert.strictEqual(w.threadId, -1);
assert.strictEqual(w.stdin, null);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this also checks that w.stdin does not throw. Can the one above be removed?

@addaleax
Copy link
Member

addaleax commented Feb 4, 2019

@addaleax
Copy link
Member

addaleax commented Feb 4, 2019

@chjj I think @sam-github’s suggestion for stdio was to make the getters not throw by removing the this[kParentSideStdio] = null line, rather than returning null from the getters, so that they always return the same values as before the worker exited? I like that idea.

@addaleax
Copy link
Member

addaleax commented Feb 6, 2019

Resume CI: https://ci.nodejs.org/job/node-test-pull-request/20625/

If this isn’t addressed in this PR, I think I’d like to land this and then apply @sam-github’s suggestion and make sure one PR doesn’t get released without the other.

addaleax pushed a commit to addaleax/node that referenced this pull request Feb 9, 2019
PR-URL: nodejs#25871
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax added a commit to addaleax/node that referenced this pull request Feb 9, 2019
This addresses review comments from
nodejs#25871.

Refs: nodejs#25871
@addaleax addaleax mentioned this pull request Feb 9, 2019
3 tasks
@addaleax
Copy link
Member

addaleax commented Feb 9, 2019

Landed in 2fc759b, see #26017 for the follow-up PR

@addaleax addaleax closed this Feb 9, 2019
targos pushed a commit that referenced this pull request Feb 10, 2019
PR-URL: #25871
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax added a commit that referenced this pull request Feb 12, 2019
This addresses review comments from
#25871.

Refs: #25871

PR-URL: #26017
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
addaleax added a commit that referenced this pull request Feb 13, 2019
This addresses review comments from
#25871.

Refs: #25871

PR-URL: #26017
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@targos targos mentioned this pull request Feb 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
worker Issues and PRs related to Worker support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants