Closes #20901: Do not record viewTime observations when we do not have 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.
upstream-sync
Grisha Kruglov 3 years ago committed by Grisha Kruglov
parent c77881988b
commit 4b01846ab0

@ -81,11 +81,17 @@ class DefaultHistoryMetadataService(
} }
override fun updateMetadata(key: HistoryMetadataKey, tab: TabSessionState) { 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 { scope.launch {
val viewTimeObservation = HistoryMetadataObservation.ViewTimeObservation( val viewTimeObservation = HistoryMetadataObservation.ViewTimeObservation(
viewTime = (System.currentTimeMillis() - tab.lastAccess).toInt() viewTime = (System.currentTimeMillis() - lastAccess).toInt()
) )
storage.noteHistoryMetadataObservation(key, viewTimeObservation) storage.noteHistoryMetadataObservation(key, viewTimeObservation)
} }

Loading…
Cancel
Save