-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Provide a --warn-on-late-sync
flag for tracing synchronous calls
#1674
Comments
could we do "warn on late sync" instead? |
@mikeal that was the idea, now that I read it the name is confusing I'll edit it. |
--no-late-sync
flag for tracing synchronous calls--warn-on-late-sync
flag for tracing synchronous calls
While this would be useful for debugging, it could never provide full coverage of various code paths (because of being a runtime flag). But that's probably inevitable. An alternative to that that would allow static check would be to provide a |
If we're adding methods it's just as easy to provide a userland solution to do this which does something like: // just one example
var fs = require("fs")
var firstTick = true; // minus when required issue, ask to require on first go
setImmediate(function(){
firstTick = false; // nest or wait more or whatever.
})
module.exports.readFileSync = function(path){
if(!nextTick && processIsNotTerminating()) console.error("Warning...... ");
return fs.readFileSync(path);
}; Or something along these lines. The only reason I'm asking for this is because such a solution would not be very practical in practice for people who're using fs. |
Would this work at the |
@trevnorris sorry for the ignorance, but what difference does it make from a user PoV? |
@benjamingr |
Thanks, from what I can tell |
@benjamingr you just omit the callback to |
Thanks, I didn't know that. That makes your question make sense to me now. This means a balance between catching more use cases and touching the C++ On Mon, May 11, 2015 at 9:41 PM, Trevor Norris notifications@github.com
|
not really. honestly we could just add an |
Then it sounds like doing it at the process.binding level makes the most sense :) Are there any C++ variables that detail that an event loop turn has already passed? |
Nope. We'd have to implement the logic internally to call a callback after the first full run of the event loop and then do a check in the C++ call like |
I think it should be on js side. |
@vkurchatkin Sure. I just want to make sure all participants in this discussion are aware that it's not a proper safety mechanism. More a convince check. |
@trevnorris Well, nothing would ever be a «proper» safety mechanism here. :-) One can always make a native module that does sync stuff. But that's ok, isn't it? I am not even sure if |
@ChALkeR My definition of "proper" is that something cannot be performed in any way from just JS. It's a very clear line that's easy to check. :) And as noted in this thread @benjamingr didn't realize that a user could bypass the normal JS check. My mentioning this was really so everyone involved realized it was possible. |
👍 My preference would be for this to be opt-out eventually, but While preference should be given for userland implementations, that's not the current standard (despite claims otherwise). This is solved/solveable in userland, but so are In general, |
Well, If you create a userland implementation that solves the issues @trevnorris raised here (access to I think no-one disagrees that The documentation currently says:
If you can come up with a way that says that in a more convincing tone then you should consider opening a docs PR. I think it would definitely make for an interesting PR and issue, and I'd also definitely be interested in seeing statistics in the wild that people actually do this for servers. |
@benjamingr Will do. Thanks for the feedback. |
Cross-linking: #1707 |
Use the --warn-on-sync flag to print a stack trace whenever a sync method is used. (e.g. fs.readFileSync()) It does not track if the warning has occurred at a specific location in the past and so will print the warning every time. This does not print the warning for the first synchronous execution of the script or during the process 'exit' event. Allowing all the require(), etc. statements to run that are necessary to prepare the environment. Fixes: nodejs#1674 PR-URL: nodejs#1707 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Petka Antonov <petka_antonov@hotmail.com>
Use the --warn-on-late-sync flag to print a stack trace whenever a sync method is used after the first tick, excluding during the process exit event. (e.g. fs.readFileSync()) It does not track if the warning has occurred at a specific location in the past and so will print the warning every time. Reason for not printing during the first tick of the appication is so all necessary resources can be required. Also by excluding synchronous calls during exit is necessary in case any data needs to be logged out by the application before it shuts down. Fixes: nodejs#1674 PR-URL: nodejs#1707 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Petka Antonov <petka_antonov@hotmail.com>
Use the --trace-sync-io flag to print a stack trace whenever a sync method is used after the first tick, excluding during the process exit event. (e.g. fs.readFileSync()) It does not track if the warning has occurred at a specific location in the past and so will print the warning every time. Reason for not printing during the first tick of the appication is so all necessary resources can be required. Also by excluding synchronous calls during exit is necessary in case any data needs to be logged out by the application before it shuts down. Fixes: nodejs#1674 PR-URL: nodejs#1707 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Petka Antonov <petka_antonov@hotmail.com>
Use the --trace-sync-io flag to print a stack trace whenever a sync method is used after the first tick, excluding during the process exit event. (e.g. fs.readFileSync()) It does not track if the warning has occurred at a specific location in the past and so will print the warning every time. Reason for not printing during the first tick of the appication is so all necessary resources can be required. Also by excluding synchronous calls during exit is necessary in case any data needs to be logged out by the application before it shuts down. Fixes: nodejs#1674 PR-URL: nodejs#1707 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Petka Antonov <petka_antonov@hotmail.com>
Use the --trace-sync-io flag to print a stack trace whenever a sync method is used after the first tick, excluding during the process exit event. (e.g. fs.readFileSync()) It does not track if the warning has occurred at a specific location in the past and so will print the warning every time. Reason for not printing during the first tick of the appication is so all necessary resources can be required. Also by excluding synchronous calls during exit is necessary in case any data needs to be logged out by the application before it shuts down. Fixes: nodejs#1674 PR-URL: nodejs#1707 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Petka Antonov <petka_antonov@hotmail.com>
This should be fixed by c1de6d2. |
Use the --trace-sync-io flag to print a stack trace whenever a sync method is used after the first tick, excluding during the process exit event. (e.g. fs.readFileSync()) It does not track if the warning has occurred at a specific location in the past and so will print the warning every time. Reason for not printing during the first tick of the appication is so all necessary resources can be required. Also by excluding synchronous calls during exit is necessary in case any data needs to be logged out by the application before it shuts down. Fixes: nodejs/node#1674 PR-URL: nodejs/node#1707 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Petka Antonov <petka_antonov@hotmail.com>
What
io.js should provide a
--warn-on-late-sync
that would detect whenever a*Sync
method has been called after the first full round of the event loop and emit a warning to stderr.Comments about semantics
process.on("exit"
code)stderr
stream, preferably with a stack traceWhy
This flag would be very useful at finding out performance bottlenecks of hidden
*Sync
calls and alerting users as well as hopefully explaining what they can do about it (switch to non-*Sync) methods.Breaking changes
This issue contradicts #1665 by making it opt-in and not opt out, the benefit is that it enables a lot of what that issue enables without breaking any existing code or forcing users to do anything about it.
Future PoV
It can also be a start for a future
--pedantic
flag that warns against the most common performance pitfalls node servers have that can't be alerted from the userland.(I opened this issue per @Fishrock123 's request of opening a separate issue)
I'm open to naming suggestions of course, I'd like this to be brought up in the TC to see if the committee doesn't find any implementation limitations or compelling reasons not to do this before any work is initiated. This is of course in addition to any comments being welcome on this issue
The text was updated successfully, but these errors were encountered: