| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Can you add tests? |
Sorry, something went wrong.
|
Ok, I will add test. And before that, i should fix another test. :-). |
Sorry, something went wrong.
|
I think it'd be better to forgo the use of child processes and just execute the timer tests directly. Also, instead of using counters, you might use common.mustCall(fn, numOfExpectedCalls) to achieve the same effect with less code (e.g. setInterval(common.mustCall(function() { .... }), 11) to expect 1 call). Then inside your setTimeout() callback where you were checking the counters, just put a process.exit(0);. |
Sorry, something went wrong.
|
But mustCall can't check how many times an internal function executed. This fix is to make sure listOnTimeout(the same as exports.active) should not be triggered again after close/unenroll in setInterval callback. |
Sorry, something went wrong.
There was a problem hiding this comment.
Nit: there's an extra set or parenthesis here.
Also I think the check should prioritize timer._idleTimeout === -1, and only check ._repeat for legacy purposes.
I'm not entirely sure checking the handle is necessary. (Aside: Timer#unref() should probably check ._idleTimeout === -1, I think.)
Sorry, something went wrong.
|
Maybe the legacy logic to prioritize to check timer._repeat is result of calling clearTimeout/clearInterval more often than close/unenroll. Check handle is necessary for unref() timer. (test case: test/parallel/test-timers-unrefd-interval-still-fires.js) |
Sorry, something went wrong.
@zhangzifa Right, neither close() no unenroll() are documented, and as such it is not suggested to use them. Checking timer._idleTimeout === -1 however, is more in line with how the rest of the code works. |
Sorry, something went wrong.
|
@Fishrock123 I agree with you that check timer._idleTimeout === -1 is enough. Someone optimized master branch and removed reuse(), it seems that this optimization should be removed and restore 'reuse()'. |
Sorry, something went wrong.
|
@zhangzifa That search has a lot of false positives, GitHub search is not very good for that.
Pardon? https://github.com/nodejs/node/blob/master/lib/timers.js#L122-L139 |
Sorry, something went wrong.
|
@Fishrock123 Sorry, my local copy is out of date. My copy is before this PR.#3407 |
Sorry, something went wrong.
There was a problem hiding this comment.
There's two extra sets or parenthesis here.
Also, could you make the change to prioritize timer._idleTimeout === -1? Thanks!
Sorry, something went wrong.
There was a problem hiding this comment.
Checking timer._idleTimeout === -1 is enough, if _idleTimeout should be set to -1 in Timeout.prototype.close when this._handle is true.
Sorry, something went wrong.
|
timer._idleTimeout === -1 should always be true when a timer is closed/canceled/unenrolled/whatever to maintain consistency. |
Sorry, something went wrong.
|
Yes, the old implementation missed to assign timer._idleTimeout as -1 when close an unrefd timer. |
Sorry, something went wrong.
|
One of the filenames has a typo in it: callbak -> callback |
Sorry, something went wrong.
There was a problem hiding this comment.
Any reason we can't just do this?:
Never mind!
Sorry, something went wrong.
listOnTimeout will be called again which should not be called anymore. When unenroll is called in timer(set by setInterval) callback, the timer still works. With this fix, the timer behaves the same as clearTimeout/clearInterval is called in callback.
|
Hey @zhangzifa, I believe this would be your first commit to core if it gets in, welcome to the project! As I think you're finding out here, messing around with timers code can be tricky and involve a lot of edge-cases that are not necessarily covered by tests. Expect this PR to continue to be picked over by other collaborators before anything's ready to be merged. It's also possible that this might go another way, such as just deprecating close() and unenroll() (I think I'd prefer this option). Please persist with us while we try and get this one right! |
Sorry, something went wrong.
|
@rvagg Happy new year! Yes, it's my first PR to this project. I'm puzzled why close() and unenroll() were exported, which i don't think necessary. Anyhow, before close() and unenroll() are removed, I think it's better to fix this fault as it is a logic fault. @Fishrock123 is refactoring timer (#4007), while this fault is still there. I am happy if another PR can fix this with a better implementation. Or @rvagg could you help involve someone who knows timer module well to review this? |
Sorry, something went wrong.
I wonder somewhat how useful the {un}enroll() / active() API possibly is. Is anyone actually using it for the means of efficiency like we do in core? I figure we should probably patch this anyways, deprecating the latter, at least, would be quite an extended process I think. |
Sorry, something went wrong.
|
Note that, before ~March 2015, we did not have /internal/ modules. |
Sorry, something went wrong.
|
Hi @Fishrock123. Incredibly someone is using {un}enroll() / active() API. |
Sorry, something went wrong.
|
Interesting. Perhaps we should still look at Timeout#close()'s existence. |
Sorry, something went wrong.
|
It seems not easy to find in which module Timeout#close() is used. I tried but failed. |
Sorry, something went wrong.
|
What's the status on this one? |
Sorry, something went wrong.
|
CI against current master: https://ci.nodejs.org/job/node-test-pull-request/4260/ |
Sorry, something went wrong.
|
@Fishrock123 ... any thoughts on this one? |
Sorry, something went wrong.
|
The tests appear to pass on master. I am quite sure I fixed this in 3f1e38c. |
Sorry, something went wrong.
|
The tests here should also not be necessary, I think. |
Sorry, something went wrong.
|
@zhangzifa Thanks anyways for reporting this! Sorry it took so long. 😅 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
-- when close called in callback, an extra active is called.
-- when unenroll called, the timer is still working