src: fix negative values in process.hrtime()#4757
src: fix negative values in process.hrtime()#4757bnoordhuis wants to merge 2 commits intonodejs:masterfrom
Conversation
|
LGTM if CI and @trevnorris are happy |
test/parallel/test-process-hrtime.js
Outdated
There was a problem hiding this comment.
I think using assert(process.hrtime([0, 999999999])[1] >= 0); as @ChALkeR suggested would be better than my test.
There was a problem hiding this comment.
assert(process.hrtime([0, 1e9 - 1])[1] >= 0); then, I think.
There was a problem hiding this comment.
well if we really want to be sure then assert(process.hrtime([0, -1 >>> 0])[1] >= 0)
There was a problem hiding this comment.
Why? I doubt that's valid input for process.hrtime.
There was a problem hiding this comment.
Because it properly decremented the seconds for any uint32 ns passed previous to my change. Therefore it should probably continue to work?
|
@bnoordhuis since the code previously was doing Whereas with this patch (and before the patch) it shows as something like EDIT: Seems the math used to not care how large a value in the uint32 range was passed. e.g. |
Fix a regression introduced in commit 89f056b ("node: improve performance of hrtime()") where the nanosecond field sometimes had a negative value when calculating the difference between two timestamps. Fixes: nodejs#4751
|
@trevnorris Is that valid?
|
|
@ChALkeR Is passing a larger seconds value supposed to return a negative value? If not then there's still a regression with this patch. |
|
@trevnorris Hm. As I read the doc, the passed value should be a result of some previous call to As it looks to me, I would say that the current behavior introduced by this patch is ok. If it could be altered to return expected values for other cases (when the passed in value is not a result of some a previous call) without considerable drawbacks (speed, code readability, etc), perhaps that should be done to keep us on the safe side. But I don't see a problem in not doing that. |
|
I see. Not trying to replicate all the old behavior, just the correct part. LGTM. CI is happy. |
|
@trevnorris Btw, I have just checked the old behavior. It also does not support values that are larger that the current ones, negative values, and arbitrary large numbers in nanosecond field. Examples (on 5.0.0): > process.hrtime()
[ 741222, 372827150 ]
> process.hrtime([0,0])
[ 741226, 252473283 ]
> process.hrtime([740000,0])
[ 1237, 26668592 ]
> process.hrtime([750000,0])
[ 1266866129, 303942850 ]
> process.hrtime([-1,0])
[ 1267616149, 293166365 ]
> process.hrtime([0,999999999])
[ 741274, 29108495 ]
> process.hrtime([0,99999999999999])
[ 741311, 514787310 ]
> process.hrtime([0,0])
[ 741404, 826126044 ]
> process.hrtime([0,-1])
[ 741402, 130741800 ]Everything that has negative values gives wrong results here, |
|
@ChALkeR If the ns field is a valid uint32 then the seconds used to decrement correctly because the values were combined in a int64 on the native side before doing the subtraction. |
|
Updated the test to just do Apropos the discussion about "user-cooked" values, I agree with @ChALkeR that GIGO applies. If you throw in the wrong numbers, don't expect the right answers to come out. |
|
Looks like the linter isn't happy. |
|
Style fix-up pushed. Running the CI one more time, last time one of the windows buildbots crapped out: https://ci.nodejs.org/job/node-test-pull-request/1320/ |
Cool. Just wanted to clear up the line between accidentally working and expected behavior. Windows CI failures are not related. |
|
LGTM |
Fix a regression introduced in commit 89f056b ("node: improve performance of hrtime()") where the nanosecond field sometimes had a negative value when calculating the difference between two timestamps. Fixes: nodejs#4751 PR-URL: nodejs#4757 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
|
Landed in 1e5a026. |
Fix a regression introduced in commit 89f056b ("node: improve performance of hrtime()") where the nanosecond field sometimes had a negative value when calculating the difference between two timestamps. Fixes: #4751 PR-URL: #4757 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
|
89f056b did not land on LTS. As such I am adding a Please feel free to chime in you you have questions or concerns |
Fix a regression introduced in commit 89f056b ("node: improve performance of hrtime()") where the nanosecond field sometimes had a negative value when calculating the difference between two timestamps. Fixes: nodejs#4751 PR-URL: nodejs#4757 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Fix a regression introduced in commit 89f056b ("node: improve
performance of hrtime()") where the nanosecond field sometimes
had a negative value when calculating the difference between two
timestamps.
Fixes: #4751
R=@trevnorris
[Can't run the CI - https://ci.nodejs.org/ times out.]