Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Closes #20901: Do not record viewTime observations when we do not hav…
Browse files Browse the repository at this point in the history
…e a set lastAccess

The bug here was that we'd try to record `now - 0` as a viewTime delta.
This isn't just an obviously wrong value to record, but it will also
overflow our storage - we'll end up with a value on disk that doesn't
fit into an i32, but HistoryMetadata.total_view_time is i32 in our Rust
struct. Once that happens, reads that touch this bad row will result in
an overflow and a crash.
  • Loading branch information
Grisha Kruglov authored and grigoryk committed Aug 19, 2021
1 parent c778819 commit 4b01846
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@ class DefaultHistoryMetadataService(
}

override fun updateMetadata(key: HistoryMetadataKey, tab: TabSessionState) {
logger.debug("Updating metadata for tab $tab")
val lastAccess = tab.lastAccess
if (lastAccess == 0L) {
logger.debug("Not updating metadata for tab $tab - lastAccess=0")
return
} else {
logger.debug("Updating metadata for tab $tab")
}

scope.launch {
val viewTimeObservation = HistoryMetadataObservation.ViewTimeObservation(
viewTime = (System.currentTimeMillis() - tab.lastAccess).toInt()
viewTime = (System.currentTimeMillis() - lastAccess).toInt()
)
storage.noteHistoryMetadataObservation(key, viewTimeObservation)
}
Expand Down

0 comments on commit 4b01846

Please sign in to comment.