Skip to content
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

fix(console): prevent panics if subscriber reports out-of-order times #295

Merged
merged 4 commits into from
Mar 7, 2022

Conversation

thombles
Copy link
Contributor

Changes duration_since and unchecked subtractions to assume
Duration::ZERO (via Default) if the alternative would be a crash.

If the subscriber reports nonsensical data this can result in negative
Durations in console's calculations, leading to panics. This has already
happened inadvertently. All changed code relates directly to received
protobuf data whose validity isn't guaranteed.

Relates to #266 (crash) and #289 (fix for root cause)


There are a handful of other unwraps/expects I'm not so sure about. These ones looked like pretty clear-cut cases where panicking is possible, undesirable, and clamping to zero is a reasonable response.

tokio-console is now at v0.1.2.
Changes duration_since and unchecked subtractions to assume
Duration::ZERO (via Default) if the alternative would be a crash.

If the subscriber reports nonsensical data this can result in negative
Durations in console's calculations, leading to panics. This has already
happened inadvertently. All changed code relates directly to received
protobuf data whose validity isn't guaranteed.

Relates to tokio-rs#266 (crash) and tokio-rs#289 (fix for root cause)
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall, this looks good to me --- i left some minor style suggestions, but it's up to you whether you think my suggested code is more readable or not. thanks!

tokio-console/src/state/async_ops.rs Outdated Show resolved Hide resolved
tokio-console/src/state/async_ops.rs Outdated Show resolved Hide resolved
Comment on lines +299 to +303
self.stats.total.unwrap_or_else(|| {
since
.duration_since(self.stats.created_at)
.unwrap_or_default()
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, take it or leave it: consider

Suggested change
self.stats.total.unwrap_or_else(|| {
since
.duration_since(self.stats.created_at)
.unwrap_or_default()
})
self.stats
.total
.or_else(|| since.duration_since(self.stats.created_at).ok())
.unwrap_or_default()

tokio-console/src/state/tasks.rs Outdated Show resolved Hide resolved
tokio-console/src/state/tasks.rs Outdated Show resolved Hide resolved
@hawkw hawkw enabled auto-merge (squash) March 7, 2022 17:47
@hawkw hawkw merged commit 80d7f42 into tokio-rs:main Mar 7, 2022
hawkw added a commit that referenced this pull request Mar 9, 2022
## 0.1.3 (2022-03-09)

#### Bug Fixes

*  exit crossterm before printing panic messages (#307)
   ([43606b9](43606b9))
*  prevent panics if subscriber reports out-of-order times (#295)
   ([80d7f42](80d7f42))

#### Features

*  add icon representing column sorting state (#301)
   ([b9e0a22](b9e0a22))
hawkw added a commit that referenced this pull request Mar 9, 2022
## 0.1.3 (2022-03-09)

#### Bug Fixes

*  exit crossterm before printing panic messages (#307)
   ([43606b9](43606b9))
*  prevent panics if subscriber reports out-of-order times (#295)
   ([80d7f42](80d7f42))

#### Features

*  add icon representing column sorting state (#301)
   ([b9e0a22](b9e0a22))
hawkw added a commit that referenced this pull request Mar 9, 2022
## 0.1.3 (2022-03-09)

#### Bug Fixes

*  exit crossterm before printing panic messages (#307)
   ([43606b9](43606b9))
*  prevent panics if subscriber reports out-of-order times (#295)
   ([80d7f42](80d7f42))

#### Features

*  add icon representing column sorting state (#301)
   ([b9e0a22](b9e0a22))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants