-
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
minor issue with timers.js #2493
Comments
Unless someone objects, I don't see any harm in doing that. Care to make a PR? |
Seems to be a reasonable change. Not sure if having a local reference is actually different from just using |
off-topic: @getify, your stable-timers auto-replaces the global timers upon loading the module. Before you do a release, it could be a good idea to change the module so it returns an object that has your Monkey-patching already defined methods and/or registering stuff to the global object is generally unsafe. It also makes your lib unusable by anything but the top-level program itself (it could not be used by modules). I'm +0 on the proposed change, though — it should make things a bit safer. |
Someone could override the exports afaik. (doesn't setting things on the object that comes out of Re: the patch: +0, though I don't really think overriding global timers is a great idea. Re: stable-timers: please let us know what issues the built-in timers have, we may be able to fix these things! :) |
thanks for the feedback. will submit a PR right away, and to be safe, will use an internal reference.
This blog post On the nature of timers explains the issues of "stability" I'm exploring fixing. Specifically, there's two stability characteristics that I'm looking at. Right now, stable-timers only implements a fix for the first, which shouldn't break anything. But the second is more disruptive, so it may end up being an optional flag that controls that. |
@getify Please don't forget to include a test case as well, if possible :-) PTAL at our contribution guide. |
quick clarification: looking at the rest of this file in question, I see a line like 119: const unenroll = exports.unenroll = function(item) { Seems like a good precedent for how I should fix my issue. However, searching the rest of the file, there are places that use Also, Basically, should I fix this stuff for consistency, or just constrain my change to only the one thing that I think is affecting my issue? |
@getify consistency should be fine to do. :) |
OK, I have a branch commit ready, I believe: https://github.com/getify/node/commit/73116effd9034dc33bdef034ceedfe2bfbe76623 However, my local environment here doesn't have the ability to actually build node (complains of too-old compiler), and even when I tried the steps in the Contributions guide for running individual tests, they failed to run Should I submit a PR as-is, or can someone else try my branch's commit and see if it's OK? Apologies for not being able to do the full steps myself. |
Sure. Here's a CI run: https://jenkins-iojs.nodesource.com/job/node-test-commit/255/
If you could sort that out somehow though, it will make it easier to contribute/test in the future. :)
Yes the tests require you to build io.js. :P |
Also, could you please run |
Hmm yeah that patch definitely doesn't work. |
Perhaps there are places in the code that have relied on being able to monkeypatch parts of this API, like the |
Definitely not. :p You forgot to assign a local |
Oh, no... actually, I accidentally changed "exports.unenroll" to "enroll()". Gah, my bad. Very sorry. |
Amended commit: https://github.com/getify/node/commit/67b552f4f2b08b4b4040fa10a607196f099f75d2 Yes, I will try to work on getting a local build environment that can build node and jslint for future contributions. |
well clearly that's not going well. :( rather than bothering you to keep running tests for me, I guess I should hold off until I can get a working local build env to test/debug myself. |
The test error appears to be:
Apparently I'm not fully clear on how globals get registered in the node environment. I see other timers tests that are able to reference globals like |
@getify ah looks like we have a thing in our common test impl that doesn't like this: https://github.com/nodejs/node/blob/master/test/common.js#L238-L325 |
Interesting. Also, I am wondering... perhaps |
That's correct. See: Lines 169 to 177 in ec6e5c7
|
OK, thanks. So if I fix |
I'm not sure, I think it should work. In any case: https://github.com/nodejs/node/blob/master/test/common.js#L315-L316 |
In my latest update:
|
Ok the reason why it errors on |
Yeah, that's what I suspected when I said earlier:
On your suggestion, I've turned off the global check for this test. :) |
How about ya make a PR? :) |
Added safe internal references for 'clearTimeout(..)', 'active(..)', and 'unenroll(..)'. Changed various API refs from 'export.*' to use these safe internal references. Now, overwriting the global API identifiers does not create potential breakage and/or race conditions. See Issue nodejs#2493.
Proposed PR to fix this is at #5882 |
Added safe internal references for 'clearTimeout(..)', 'active(..)', and 'unenroll(..)'. Changed various API refs from 'export.*' to use these safe internal references. Now, overwriting the global API identifiers does not create potential breakage and/or race conditions. See Issue #2493. PR-URL: #5882 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Fixes: #2493
Added safe internal references for 'clearTimeout(..)', 'active(..)', and 'unenroll(..)'. Changed various API refs from 'export.*' to use these safe internal references. Now, overwriting the global API identifiers does not create potential breakage and/or race conditions. See Issue #2493. PR-URL: #5882 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Fixes: #2493
This line:
Instead of calling
exports.clearTimeout(..)
, or even better, having a local identifier pointing at that function, this line is making a call that relies on resolving to the identifier on theglobal
object.That works OK until a lib like mine, stable-timers, comes along and replaces those global timer API methods. When using my lib, I'm getting race conditions where sometimes this line 270 throws an exception that
timer._repeat
is not a function.Could we make a small tweak to timers.js to have line 290 reference a reliable internal reference for
clearTimeout
?The text was updated successfully, but these errors were encountered: