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

domain: runtime deprecate MakeCallback #17417

Closed
wants to merge 2 commits into from
Closed

domain: runtime deprecate MakeCallback #17417

wants to merge 2 commits into from

Conversation

AndreasMadsen
Copy link
Member

Users of MakeCallback that adds the domain property to carry context,
should start using the async_context variant of MakeCallback or the
AsyncResource class.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

domain

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Dec 1, 2017
@AndreasMadsen AndreasMadsen added domain Issues and PRs related to the domain subsystem. addons Issues and PRs related to native addons. dont-land-on-v4.x and removed c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Dec 1, 2017
@AndreasMadsen
Copy link
Member Author


Users of MakeCallback that adds the domain property to carry context,
should start using the async_context variant of MakeCallback or the
AsyncResource class.
Copy link
Member

Choose a reason for hiding this comment

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

Back-ticks around MakeCallback() and AsyncResource?

src/env.cc Outdated
@@ -262,6 +262,12 @@ bool Environment::EmitNapiWarning() {
return current_value;
}

bool Environment::EmitDomainWarning() {
Copy link
Member

Choose a reason for hiding this comment

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

Not a great name. The imperative suggests it performs an action but it's really a getter, although one with side effects (which itself is somewhat objectionable.)

At the very least call it something like ShouldEmitDomainWarning(), and look into separating the check and the update. Since you're only using it in one place, I'd split it in a getter and setter and call the setter explicitly after emitting the warning.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hehe. Basically just copied EmitNapiWarning :D

src/node.cc Outdated
"Using a domain property in MakeCallback is deprecated. Use the "
"async_context variant of MakeCallback or the AsyncResource class "
"instead.",
"DEPXXXX");
Copy link
Member

Choose a reason for hiding this comment

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

4 space indent for line continuations and env should arguably go on a line of its own.

<a id="DEPXXXX"></a>
### MakeCallback with domain property

Users of MakeCallback that adds the domain property to carry context,
Copy link
Contributor

Choose a reason for hiding this comment

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

that adds -> that add

<a id="DEPXXXX"></a>
### MakeCallback with domain property

Users of MakeCallback that adds the domain property to carry context,
Copy link
Contributor

Choose a reason for hiding this comment

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

MakeCallback, domain, etc. should be in backticks I think.

@AndreasMadsen
Copy link
Member Author

Thanks. Please check again.

src/node.cc Outdated
"Using a domain property in MakeCallback is deprecated. Use the "
"async_context variant of MakeCallback or the AsyncResource class "
"instead.",
"DEPXXXX");
Copy link
Member

Choose a reason for hiding this comment

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

Can you indent everything by 4 spaces?


Users of `MakeCallback` that add the `domain` property to carry context,
should start using the `async_context` variant of `MakeCallback` or the
`AsyncResource` class.
Copy link
Member

Choose a reason for hiding this comment

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

… or CallbackScope?

Copy link
Member

Choose a reason for hiding this comment

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

minor nit, DEP00XX in order for the tooling to catch these on release builds (there's a script that looks for the DEP00XX pattern specifically)

src/node.cc Outdated

Local<Object> process = env->process_object();
MaybeLocal<Value> emit_warning = process->Get(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "emitWarning"));
Copy link
Member

Choose a reason for hiding this comment

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

I would probably move the FIXED_ONE_BYTE_STRINGs here into the list in env.h?

src/node.cc Outdated
Local<Value> args[3];
args[0] = node::OneByteString(env->isolate(), warning);
args[1] = FIXED_ONE_BYTE_STRING(env->isolate(), "DeprecationWarning");
args[2] = node::OneByteString(env->isolate(), deprecation_code);
Copy link
Member

Choose a reason for hiding this comment

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

deprecation_code might make more sense as an internalized string (i.e. using String::NewFromOneByte with v8::NewStringType::kInternalized directly)?

src/node.cc Outdated

// MakeCallback() unneeded, because emitWarning is internal code, it calls
// process.emit('warning', ..), but does so on the nextTick.
f.As<v8::Function>()->Call(process, arraysize(args), args);
Copy link
Member

Choose a reason for hiding this comment

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

Can you use the overload of Call() that takes a context argument?

src/node.cc Outdated

Local<Value> f;

if (!emit_warning.ToLocal(&f)) return;
Copy link
Member

Choose a reason for hiding this comment

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

If emit_warning is empty, we should probably return immediately after that. Creating handles to strings in between the failure and returning is probably no big deal, but at some point somebody might think it’s okay to slip in code that potentially calls back into JS instead?

Either way, one issue here is that ProcessEmitDeprecationWarning has no way of signaling its caller whether it leaves an exception pending or not (i.e. if emit_warning is empty or the ->Call() below returned an empty result).

I think the options for that are:

  • Return Maybe<bool>, like the V8 API does, which is Just(true) on success and Nothing<bool>() on failure, and leave it for the caller to handle the issue.
  • Use .ToLocalChecked() on everything. The big downside is that emitting deprecation warnings with --throw-deprecation on the command line does throw an error as part of regular operations.

src/node.cc Outdated
FIXED_ONE_BYTE_STRING(env->isolate(), "emitWarning"));

Local<Value> args[3];
args[0] = node::OneByteString(env->isolate(), warning);
Copy link
Member

Choose a reason for hiding this comment

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

UTF-8, to be a bit more future-proof? :)

@AndreasMadsen
Copy link
Member Author

@addaleax I basically just modified the code from ProcessEmitWarning 😂 .

@addaleax
Copy link
Member

addaleax commented Dec 1, 2017

@AndreasMadsen I see … 😄 The comments related to string creation are certainly optional and you can ignore them to keep parity (and/or leave a TODO comment for me 😉).

But ProcessEmitWarning() really should not do exception handling the way it does it; and at least with deprecation warnings, this becomes a real problem due to --throw-deprecation

@AndreasMadsen
Copy link
Member Author

@addaleax That's fair. Let's fix ProcessEmitWarning first, then I will update this PR. This PR is not exactly pressing or prone to lots of merge conflicts.

@addaleax
Copy link
Member

addaleax commented Dec 1, 2017

@AndreasMadsen Just so we’re on the same page, what’s the next step? One of us opens a separate PR with those changes? Do you do that or want me to do that?

@AndreasMadsen
Copy link
Member Author

AndreasMadsen commented Dec 1, 2017

@addaleax Yes. Go ahead and make it. I might have a few questions just to learn :)

@Trott Trott added the semver-major PRs that contain breaking changes and should be released in the next major version. label Dec 1, 2017
@Trott
Copy link
Member

Trott commented Dec 1, 2017

IIRC, policy is that runtime deprecations are always treated as breaking changes so I've labeled this semver-major. That said, the TSC can opt to treat it as a non-breaking change, so feel free to put on the TSC agenda if anyone thinks it ought to land in 9.x.

@AndreasMadsen AndreasMadsen added the blocked PRs that are blocked by other issues or PRs. label Dec 8, 2017
@AndreasMadsen AndreasMadsen added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 19, 2017
Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

LGTM if a test is added

MylesBorins pushed a commit that referenced this pull request Jan 8, 2018
- Handle exceptions when getting `process.emitWarning` or when
  calling it properly
- Add `Maybe<bool>` to the return type, like the V8 API uses it
  to indicate failure conditions
- Update call sites to account for that and clean up/return to JS
  when encountering an error
- Add an internal `ProcessEmitDeprecationWarning()` sibling
  for use in #17417,
  with common code extracted to a helper function
- Allow the warning to contain non-Latin-1 characters. Since the
  message will usually be a template string containing data passed
  from the user, this is the right thing to do.
- Add tests for the failure modes (except string creation failures)
  and UTF-8 warning messages.

PR-URL: #17420
Refs: #17417
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@jasnell
Copy link
Member

jasnell commented Jan 10, 2018

ping @AndreasMadsen ... can you add a test?

@AndreasMadsen
Copy link
Member Author

@AndreasMadsen
Copy link
Member Author

@AndreasMadsen
Copy link
Member Author

@BridgeAR @jasnell I added the test. Can you approve it?

@joyeecheung
Copy link
Member

Ping @AndreasMadsen this needs a rebase, thanks

@AndreasMadsen
Copy link
Member Author

@joyeecheung Will you review it if I rebase it?

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

Still LGTM, by the way.

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

needs a rebase and my comment should be looked at.


// Warning is emitted when domain property is used and domain is enabled
makeCallback({ domain: d }, common.mustCall(function() {
assert.strictEqual(latestWarning, null);
Copy link
Member

@BridgeAR BridgeAR Jan 19, 2018

Choose a reason for hiding this comment

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

I am not certain when exactly the warning should be emitted but from the comment itself it seems to me that latestWarning should not be null. If it should be, it would be good to add a test that actually tests for notStrictEqual.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, this is odd

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

Ping @AndreasMadsen

@AndreasMadsen
Copy link
Member Author

Yeah, I was waiting for #18291 to land

@BridgeAR
Copy link
Member

BridgeAR commented Feb 7, 2018

Ping @AndreasMadsen again. It landed 8 days ago ;-)

Users of MakeCallback that adds the domain property to carry context,
should start using the async_context variant of MakeCallback or the
AsyncResource class.
@AndreasMadsen
Copy link
Member Author

@BridgeAR Complete rewrote the implementation, please check.

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

@AndreasMadsen
Copy link
Member Author

fixed lint issues :D

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

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

LGTM

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 8, 2018
@AndreasMadsen
Copy link
Member Author

Landed in 14bc3e2

MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
Users of MakeCallback that adds the domain property to carry context,
should start using the async_context variant of MakeCallback or the
AsyncResource class.

PR-URL: nodejs#17417
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addons Issues and PRs related to native addons. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. domain Issues and PRs related to the domain subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet