-
Notifications
You must be signed in to change notification settings - Fork 13.3k
std: Fix sub-second Condvar::wait_timeout_ms #27373
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
cc @carllerche r? @brson Also nominating for beta as this is a somewhat serious bug |
cc @sfackler |
let seconds = dur.secs() as libc::time_t; | ||
let timeout = match sys_now.tv_sec.checked_add(seconds) { | ||
|
||
let timeout = match (sys_now.tv_sec + extra).checked_add(seconds) { |
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.
Only one checked_add here, not 2?
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.
I figured that gettimeofday
won't return a value that is 1 away from overflowing, but we don't control seconds + sys_now.tv_sec
so that still needs to be checked.
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 will if you set your system clock that way :P
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.
I agree with @sfackler. The bad input is possible and should be accounted for.
The API we're calling requires us to pass an absolute point in time as an argument (`pthread_cond_timedwait`) so we call `gettimeofday` ahead of time to then add the specified duration to. Unfortuantely the current "add the duration" logic forgot to take into account the current time's sub-second precision (e.g. the `tv_usec` field was ignored), causing sub-second duration waits to return spuriously.
9803374
to
43b2c47
Compare
Updated to use |
@bors: r+ |
📌 Commit 43b2c47 has been approved by |
…=brson The API we're calling requires us to pass an absolute point in time as an argument (`pthread_cond_timedwait`) so we call `gettimeofday` ahead of time to then add the specified duration to. Unfortuantely the current "add the duration" logic forgot to take into account the current time's sub-second precision (e.g. the `tv_usec` field was ignored), causing sub-second duration waits to return spuriously.
@bors: p=1 (merging to beta) |
The API we're calling requires us to pass an absolute point in time as an
argument (
pthread_cond_timedwait
) so we callgettimeofday
ahead of time tothen add the specified duration to. Unfortuantely the current "add the duration"
logic forgot to take into account the current time's sub-second precision (e.g.
the
tv_usec
field was ignored), causing sub-second duration waits to returnspuriously.