std: Fix sub-second Condvar::wait_timeout_ms#27373
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 |
src/libstd/sys/unix/condvar.rs
Outdated
There was a problem hiding this comment.
Only one checked_add here, not 2?
There was a problem hiding this comment.
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.
It will if you set your system clock that way :P
There was a problem hiding this comment.
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 callgettimeofdayahead 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_usecfield was ignored), causing sub-second duration waits to returnspuriously.