-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
src: log warning on process.binding('natives') #2741
src: log warning on process.binding('natives') #2741
Conversation
// graceful-fs < 4 evals process.binding('natives').fs, which prohibits | ||
// using internal modules in that module. Encourage people to upgrade. | ||
fprintf(stderr, "(node) process.binding('natives') is deprecated.\n"); | ||
fprintf(stderr, "(node) If you use graceful-fs < 4, please update.\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we really say this in the warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the sole reason for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't know if other modules do the same. Why should we care only about graceful-fs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it's probably the most used offender. The only other projects I could find with Github's (admittedly terrible) code search is an sys / util shim (which does seem to get copied around a lot, there's that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I dislike calling out a specific module here, graceful-fs is really heavily used and is causing specific problems here. Perhaps the compromise is to leave the note in but put a //TODO: Remove by v6
or similar in there just to mark it as a temporary message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 @rvagg
|
node::Utf8Value name(env->isolate(), frame->GetScriptName()); | ||
fprintf(stderr, "(node) at %s:%d\n", *name, frame->GetLineNumber()); | ||
} | ||
fflush(stderr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stderr is not buffered right? Should we really flush it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libc I/O can be buffered, that's why the fflush() is there.
This kind of kicks the can down the road with |
I have an idea how we can deprecate public access to process.binding |
For background, the reason for this PR is that I want to pre-compile our JS code using the V8 extras infrastructure. At that point |
I think I'm ok with this. Making guarantees about our source being exposed at run-time is a ludicrous idea. |
LGTM. |
Thanks @jasnell. I plan to merge this early next week so if anyone has strong feelings, now is the time to speak up. |
I have strong feelings about this being a good idea. 👍 |
@bnoordhuis I propose to use #2768 for this. It's not necessary to deprecate whole |
Fine by me, as long as it gets done. Closing. |
@bnoordhuis It looks like it was actually never done, and #2768 was closed a few days ago. Perhaps we should reopen this? |
If this goes forward it should be updated to make use of the |
This is used by old versions of graceful-fs but will stop working in the not too distant future. Print a warning so people know to upgrade.
6eab98e
to
35a62c5
Compare
Rebased. Added a second commit that takes a different approach: check if the topmost JS frame is a builtin script.
Why? We don't do that for other warnings in C++ code either. |
fprintf(stderr, | ||
"(node:%d) process.binding('natives') is deprecated.\n", pid); | ||
fprintf(stderr, | ||
"(node:%d) If you use graceful-fs < 4, please update.\n", pid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do recent versions of graceful-fs@3 still trigger this? It was updated just recently.
Update: they do, I verified that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another question: do we need to specifically note graceful-fs here? It's not the only package that uses process.binding('natives')
, and that could lead people away from the actual issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flashback: #2741 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bnoordhuis yes, but see the list at #2741 (comment), that wasn't considered back then.
Also, graceful-fs@2 and graceful-fs@3 usage significantly decreased in past months.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I could check if the caller is graceful-fs and customize the error based on that but meh. I have to be selective with my time in the next few weeks so I'm probably not going to expend too much effort on this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't have the time to work on it, I am willing to take it over.
So that it can be consistently handled as a runtime deprecation just like any other deprecation warning we print. As illustrated by #8270, it's pretty trivial and has the built-in benefit of working with Update ... for instance, with the patch as it is currently:
Using |
I found 268 lines in 147 packages using
|
auto caller_script_id = GetCallerScriptId(env->isolate()); | ||
if (!IsInternalScriptId(env, caller_script_id)) { | ||
// graceful-fs < 4 evals process.binding('natives').fs, which prohibits | ||
// using internal modules in that module. Encourage people to upgrade. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which prohibits using internal modules in that module.
This is not accurate any more, they evaded that, and it now reevalutes internal modules with more dark magic, internal API usage, and relying on implementation details.
Yes. Please be specific if you think there is something unintentional in there. |
@bnoordhuis Ok, I meant that the warning looks like too heavy to me, and most of those is cosumed by lines that do not bring much value (i.e. |
Btw, one more thing: 4 packages actually assign to Could we stop that, like now, without waiting for a whole major release cycle? This shouldn't get misused even more. |
That would be nice, making props non-writable and non-configurable should be enough |
+1 ... especially if we know we can do it without breaking non-test code. |
I added the stack trace based on prior experience that if you don't, people are going to complain it's impossible to find out what is causing the warning. |
Makes sense. But could we strip out lines that match |
Added a commit that does that (but in a better way than pattern matching strings.) |
@bnoordhuis Thanks! Upd: yes, the warning looks good now. |
@bnoordhuis Sorry, I have another warning message stylistic question. How much extra code would it be to print the Upd: e.g. webpack does that on it's own, without graceful-fs. I can't guarantee that that exact code is commonly triggered, but webpack has almost 2 millon downloads per month. It's not an argument against this PR (the fix for webpack is straightforward), it's an argument for not confusing those users with graceful-fs specific mesages. Btw — is this semver-patch or semver-major? |
I'm -1 on this as is given that it is printed as a deprecation but does not properly follow the |
@jasnell, would you change your mind if this would follow the command-line flags? |
Yep... see #2741 (comment) |
However, please keep in mind that the new fix for graceful-fs uses the natives module which uses |
@jasnell, older graceful-fs@3 versions used |
Yep, just wanted to make sure it was noted. |
The JS API has no way to do the internal stack frame filtering that @ChALkeR requested, and besides, other deprecation warnings from C++ (e.g. deprecated Template::Set usage) don't use it either. I could argue the PR in its current shape is more consistent with existing practices than it would be if I included your suggestion. |
At the very least |
Just a note: I would be fine with not filtering if printing the trace would be behind a flag. I don't have any specific opinion on printing from js vs printing from the C++ side here at the moment, though. |
c133999
to
83c7a88
Compare
This is used by old versions of graceful-fs but will stop working in the
not too distant future. Print a warning so people know to upgrade.
CI: https://ci.nodejs.org/job/node-test-pull-request/268/