-
Notifications
You must be signed in to change notification settings - Fork 107
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
Add stack trace to code recursively scheduling timers #325
Add stack trace to code recursively scheduling timers #325
Conversation
Codecov Report
@@ Coverage Diff @@
## master #325 +/- ##
==========================================
+ Coverage 93.12% 93.52% +0.39%
==========================================
Files 1 1
Lines 553 587 +34
==========================================
+ Hits 515 549 +34
Misses 38 38
Continue to review full report at Codecov.
|
Could we just keep track of the last scheduled timer instead of all scheduled timers? Not sure how much that matters |
9a92f55
to
290426e
Compare
Another thought, this is mostly meant to catch timers added while running timers. Could we add some flag internally that's set to |
290426e
to
033e9fb
Compare
@SimenB Thanks for the feedback! |
no time (parental leave) at the moment to look at PRs, sorry. |
src/fake-timers-src.js
Outdated
" timers, assuming an infinite loop!" | ||
); | ||
|
||
var sliceSize = job.type ? 4 : 3; |
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 would be ideal to calculate this by looking for ourselves in the stack trace rather than setting prefixed sizes. This can fail based on adding new jobs.
src/fake-timers-src.js
Outdated
|
||
var sliceSize = job.type ? 4 : 3; | ||
|
||
infiniteLoopError.stack = |
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.
Some environments don't have a writeable stack property - so it would be better to wrap this in a try/catch and to use defineProperty
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.
In particular we had this issue several times in bluebird which also mutates stacks
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.
Hey, left a few comments.
Code looks good in principle - the things I'd want to see to approve (other collaborators may approve before I'm not blocking):
- Tests that check a larger chunk of the stack (so we're sure this doesn't break) .
- Dealing with a non-writeable stack property.
I'll approve if those two get addressed even without calculating the slice size automatically.
Also:
The actual implementation logic lgtm |
@benjamingr Awesome, thanks for the feedback! I'll take a run through it tomorrow night 👍 |
825a19b
to
0a5b187
Compare
Using
Doing this by running through the stack line by line, checking the line matches
Apologies, I wasn't 100% sure on what this was asking, so I've added more tests to cover If this was referring to checking more of the stack trace itself, the tests are checking that we're getting the expected method at the top of the stack - but we can't check the filename as it'll be |
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.
Latest version LGTM. Thanks for this - this makes debugging easier :)
Let's give other members a few days to respond before merging.
Hey, I wanted to merge and it looks like there is a merge conflict - can you please take a look? |
Use stack information for jobs and timers to provide more context when an infinite loop error is thrown. Fixes sinonjs#230
Use a flag when approaching infinite loop detection which will enable an error object to be attached to the job, which can then be used for generating the stack output.
- Safely update stack property using `defineProperty`, wrapped in try/catch - Tests for more clock functions to confirm stack trace provided - Stack trace slice automatically calculated based on clock function position
- Use global setInterval and setImmediate to match setTimeout use - Remove unnecessary duration parameter from setImmediate and setImmediate
955361e
to
d95493e
Compare
@benjamingr Rebased off |
Thanks! |
This broke the builds on Safari, IE and Firefox. It needs some patching before we can release it as part of a new release. The "cloud" tests are only run on |
@benjamingr Do you think you can get this in again, after fixing the issues that broke the build? Was some good work done here by @alistairjcbrown. Shame to let it go to waste. |
Yeah I agree - I just didn't have a ton of free time recently :/ Maybe @itayperry wants to pick up readding this? (I can guide, I just have little free time to dedicate to this myself) |
I would be happy to take part in this @benjamingr 🎉 |
) * Add stack trace to code recursively scheduling timers Use stack information for jobs and timers to provide more context when an infinite loop error is thrown. Fixes #230 Add flag for approaching infinite loop Use a flag when approaching infinite loop detection which will enable an error object to be attached to the job, which can then be used for generating the stack output. Update for PR feedback - Safely update stack property using `defineProperty`, wrapped in try/catch - Tests for more clock functions to confirm stack trace provided - Stack trace slice automatically calculated based on clock function position Remove unnecessary durations and use globals - Use global setInterval and setImmediate to match setTimeout use - Remove unnecessary duration parameter from setImmediate and setImmediate add use of prettier Firefox and Chrome tests pass after RegExp fix Chrome shows stack messages differently, and uses the words: 'at' and 'Object', Firefox does not - that has created two problems: first, the stack trace messages that are shown to the user are a bit different (Firefox always has at least one more line at the start of the stack list - usually internal functions that are not supposed to appear). Second, the RegExp tried to match parts of the strings that only exist in Chrome, failing the Firefox tests) prettier used * small RegExp fix for node env + linting * improving test-coverage statistics * at attempt to ignore certain condition in nyc coverage Co-authored-by: Alistair Brown <[email protected]>
Purpose (TL;DR) - mandatory
Fix issue #230 by using stack information for jobs and timers to provide more context when an infinite loop error is thrown.
Solution - optional
This solution works by adding a
stack
property to jobs and tasks. This data can then be used, if an infinite loop is detected, to set the stack of the throwninfiniteLoopError
.Example stack trace from test run