unix: fix utime/futime timestamp rounding errors#2747
Conversation
| t.tv_sec = x; | ||
| t.tv_nsec = 1e9 * uv__frac(x); | ||
|
|
||
| /* TODO(bnoordhuis) Remove this. utimesat() has nanosecond resolution but we |
There was a problem hiding this comment.
Out of curiosity, when can we remove this? I'm only asking because WASI wants nanosecond precision.
There was a problem hiding this comment.
I'll merge this and open a PR that removes it.
3745b86 to
c57bf54
Compare
|
FTR, this is how the test fails on Windows: |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
Perhaps our time computation is overflowing in a similar way here https://github.com/libuv/libuv/blame/master/src/win/fs.c#L146? or just doesn't like the casts to unsigned? or the filesystem doesn't support negative times? |
`uv_fs_utime()` and `uv_fs_futime()` receive the timestamp as a `double` and then convert it to `struct timeval` or `struct timespec` where necessary but the calculation for the sub-second part exhibited rounding errors for dates in the deep past or the far-flung future, causing the timestamps to be off by sometimes over half a second. Fixes: nodejs/node#32369 (partially) PR-URL: libuv#2747
`uv_fs_utime()` and `uv_fs_futime()` receive the timestamp as a `double` and then convert it to `struct timeval` or `struct timespec` where necessary but the calculation for the sub-second part exhibited rounding errors for dates in the deep past or the far-flung future, causing the timestamps to be off by sometimes over half a second on unix, or to be reinterpreted as unsigned and end up off by more than just sign but many also decades. Fixes: nodejs/node#32369 (partially) PR-URL: libuv#2747 Co-authored-by: Jameson Nash <vtjnash@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Without `volatile`, the x87 hardware may re-organize the comparison math and end up with the wrong answer.
Fixes: one bullet point item of
libuv#2655 and the tests from
libuv#849 in certain build configurations
PR-URL: libuv#2747
c57bf54 to
03d712b
Compare
|
I ended up changing some of the details of the PR (in particular, |
`check_utime()` already calls `uv_fs_stat()`, no point in doing it twice. PR-URL: libuv#2747 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
`uv_fs_utime()` and `uv_fs_futime()` receive the timestamp as a `double` and then convert it to `struct timeval` or `struct timespec` where necessary but the calculation for the sub-second part exhibited rounding errors for dates in the deep past or the far-flung future, causing the timestamps to be off by sometimes over half a second on unix, or to be reinterpreted as unsigned and end up off by more than just sign but many also decades. Fixes: nodejs/node#32369 (partially) PR-URL: libuv#2747 Co-authored-by: Jameson Nash <vtjnash@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Without `volatile`, the x87 hardware may re-organize the comparison math and end up with the wrong answer.
Fixes: one bullet point item of
libuv#2655 and the tests from
libuv#849 in certain build configurations
PR-URL: libuv#2747
03d712b to
3e61a15
Compare
|
Tests are a bit too aggressive for some of our CI filesystems, but intended to show that it works correctly on at least some of the configurations. Will need to back off on those slightly then merge this. Anyone willing to review? |
|
bump for (re)review |
`check_utime()` already calls `uv_fs_stat()`, no point in doing it twice. PR-URL: libuv#2747 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
`uv_fs_utime()` and `uv_fs_futime()` receive the timestamp as a `double` and then convert it to `struct timeval` or `struct timespec` where necessary but the calculation for the sub-second part exhibited rounding errors for dates in the deep past or the far-flung future, causing the timestamps to be off by sometimes over half a second on unix, or to be reinterpreted as unsigned and end up off by more than just sign but many also decades. Fixes: nodejs/node#32369 (partially) PR-URL: libuv#2747 Co-authored-by: Jameson Nash <vtjnash@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Without `volatile`, the x87 hardware may re-organize the comparison math and end up with the wrong answer.
Fixes: one bullet point item of
libuv#2655 and the tests from
libuv#849 in certain build configurations
PR-URL: libuv#2747
3e61a15 to
d8feea7
Compare
`uv_fs_utime()` and `uv_fs_futime()` receive the timestamp as a `double` and then convert it to `struct timeval` or `struct timespec` where necessary but the calculation for the sub-second part exhibited rounding errors for dates in the deep past or the far-flung future, causing the timestamps to be off by sometimes over half a second on unix, or to be reinterpreted as unsigned and end up off by more than just sign but many also decades. Fixes: nodejs/node#32369 (partially) PR-URL: libuv#2747 Co-authored-by: Jameson Nash <vtjnash@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Without `volatile`, the x87 hardware may re-organize the comparison math and end up with the wrong answer.
Fixes: one bullet point item of
libuv#2655 and the tests from
libuv#849 in certain build configurations
PR-URL: libuv#2747
d8feea7 to
703c7ee
Compare
|
I already signed off on Ben's changes, but my LGTM still stands if you want to move this forward. |
|
Thanks. I'd changed enough about it that I felt it needed a re-confirmation before merging. I've got most tests functioning now (https://ci.nodejs.org/job/libuv-test-commit/2088/), but need to update a couple more. |
5fed6f5 to
bed5761
Compare
`uv_fs_utime()` and `uv_fs_futime()` receive the timestamp as a `double` and then convert it to `struct timeval` or `struct timespec` where necessary but the calculation for the sub-second part exhibited rounding errors for dates in the deep past or the far-flung future, causing the timestamps to be off by sometimes over half a second on unix, or to be reinterpreted as unsigned and end up off by more than just sign but many also decades. Fixes: nodejs/node#32369 (partially) PR-URL: libuv#2747 Co-authored-by: Jameson Nash <vtjnash@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Without `volatile`, the x87 hardware may re-organize the comparison math and end up with the wrong answer.
Fixes: one bullet point item of
libuv#2655 and the tests from
libuv#849 in certain build configurations
PR-URL: libuv#2747
bed5761 to
a3a1669
Compare
|
Final CI, for most recent fixup commit is not showing any related failures: https://ci.nodejs.org/job/libuv-test-commit/2090/. Should be ready for someone to land now! |
`check_utime()` already calls `uv_fs_stat()`, no point in doing it twice. PR-URL: libuv#2747 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
`uv_fs_utime()` and `uv_fs_futime()` receive the timestamp as a `double` and then convert it to `struct timeval` or `struct timespec` where necessary but the calculation for the sub-second part exhibited rounding errors for dates in the deep past or the far-flung future, causing the timestamps to be off by sometimes over half a second on unix, or to be reinterpreted as unsigned and end up off by more than just sign but many also decades. Fixes: nodejs/node#32369 (partially) PR-URL: libuv#2747 Co-authored-by: Jameson Nash <vtjnash@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Without `volatile`, the x87 hardware may re-organize the comparison math
and end up with the wrong answer.
Fixes: one bullet point item of
libuv#2655 and the tests from
libuv#849 in certain build configurations
PR-URL: libuv#2747
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
a3a1669 to
dde9815
Compare
`check_utime()` already calls `uv_fs_stat()`, no point in doing it twice. PR-URL: libuv#2747 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
`uv_fs_utime()` and `uv_fs_futime()` receive the timestamp as a `double` and then convert it to `struct timeval` or `struct timespec` where necessary but the calculation for the sub-second part exhibited rounding errors for dates in the deep past or the far-flung future, causing the timestamps to be off by sometimes over half a second on unix, or to be reinterpreted as unsigned and end up off by more than just sign but many also decades. Fixes: nodejs/node#32369 (partially) PR-URL: libuv#2747 Co-authored-by: Jameson Nash <vtjnash@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Without `volatile`, the x87 hardware may re-organize the comparison math
and end up with the wrong answer.
Fixes: one bullet point item of
libuv#2655 and the tests from
libuv#849 in certain build configurations
PR-URL: libuv#2747
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
`check_utime()` already calls `uv_fs_stat()`, no point in doing it twice. PR-URL: libuv/libuv#2747 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
`uv_fs_utime()` and `uv_fs_futime()` receive the timestamp as a `double` and then convert it to `struct timeval` or `struct timespec` where necessary but the calculation for the sub-second part exhibited rounding errors for dates in the deep past or the far-flung future, causing the timestamps to be off by sometimes over half a second on unix, or to be reinterpreted as unsigned and end up off by more than just sign but many also decades. Fixes: nodejs/node#32369 (partially) PR-URL: libuv/libuv#2747 Co-authored-by: Jameson Nash <vtjnash@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Without `volatile`, the x87 hardware may re-organize the comparison math
and end up with the wrong answer.
Fixes: one bullet point item of
libuv/libuv#2655 and the tests from
libuv/libuv#849 in certain build configurations
PR-URL: libuv/libuv#2747
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
`check_utime()` already calls `uv_fs_stat()`, no point in doing it twice. PR-URL: libuv/libuv#2747 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
`uv_fs_utime()` and `uv_fs_futime()` receive the timestamp as a `double` and then convert it to `struct timeval` or `struct timespec` where necessary but the calculation for the sub-second part exhibited rounding errors for dates in the deep past or the far-flung future, causing the timestamps to be off by sometimes over half a second on unix, or to be reinterpreted as unsigned and end up off by more than just sign but many also decades. Fixes: nodejs/node#32369 (partially) PR-URL: libuv/libuv#2747 Co-authored-by: Jameson Nash <vtjnash@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Without `volatile`, the x87 hardware may re-organize the comparison math
and end up with the wrong answer.
Fixes: one bullet point item of
libuv/libuv#2655 and the tests from
libuv/libuv#849 in certain build configurations
PR-URL: libuv/libuv#2747
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
uv_fs_utime()anduv_fs_futime()receive the timestamp asa
doubleand then convert it tostruct timevalorstruct timespecwhere necessary but the calculation for the sub-second part exhibited
rounding errors for dates in the deep past or the far-flung future,
causing the timestamps to be off by sometimes over half a second.
Fixes: nodejs/node#32369 (partially)
CI: https://ci.nodejs.org/job/libuv-test-commit/1806/CI: https://ci.nodejs.org/job/libuv-test-commit/1817/CI: https://ci.nodejs.org/job/libuv-test-commit/1825/