Skip to content

std: Fix sub-second Condvar::wait_timeout_ms - #27373

Merged
bors merged 1 commit into
rust-lang:masterfrom
alexcrichton:fix-wait-timeout-ms
Jul 29, 2015
Merged

std: Fix sub-second Condvar::wait_timeout_ms#27373
bors merged 1 commit into
rust-lang:masterfrom
alexcrichton:fix-wait-timeout-ms

Conversation

@alexcrichton

Copy link
Copy Markdown
Member

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.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton

Copy link
Copy Markdown
MemberAuthor

cc @carllerche

r? @brson

Also nominating for beta as this is a somewhat serious bug

@alexcrichtonalexcrichton added beta-nominated Nominated for backporting to the compiler in the beta channel. T-libs-api [DEPRECATED; DO NOT USE] labels Jul 29, 2015
@alexcrichton

Copy link
Copy Markdown
MemberAuthor

cc @sfackler

Comment threadsrc/libstd/sys/unix/condvar.rs Outdated

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
MemberAuthor

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.

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor

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.

@brsonbrson added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jul 29, 2015
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.
@alexcrichton

Copy link
Copy Markdown
MemberAuthor

Updated to use checked_add on both additions

@brson

Copy link
Copy Markdown
Contributor

@bors: r+

@bors

bors commented Jul 29, 2015

Copy link
Copy Markdown
Collaborator

📌 Commit 43b2c47 has been approved by brson

Manishearth added a commit to Manishearth/rust that referenced this pull request Jul 29, 2015
…=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.
@brsonbrson mentioned this pull request Jul 29, 2015
@alexcrichton

Copy link
Copy Markdown
MemberAuthor

@bors: p=1 (merging to beta)

bors added a commit that referenced this pull request Jul 29, 2015
@bors
bors merged commit 43b2c47 into rust-lang:masterJul 29, 2015
@brsonbrson added beta-accepted Accepted for backporting to the compiler in the beta channel. and removed beta-accepted Accepted for backporting to the compiler in the beta channel. beta-nominated Nominated for backporting to the compiler in the beta channel. labels Jul 30, 2015
@alexcrichton
alexcrichton deleted the fix-wait-timeout-ms branch August 17, 2015 19:50
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta-acceptedAccepted for backporting to the compiler in the beta channel.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@alexcrichton@rust-highfive@brson@bors@sfackler@nikomatsakis