clamp instead of reject max expiration time

This commit is contained in:
John Smith 2023-12-10 16:29:52 -05:00 committed by Christien Rioux
parent 9c0c7cf0b2
commit c33b00fe32
2 changed files with 14 additions and 8 deletions

View File

@ -642,14 +642,17 @@ impl StorageManager {
expiration.as_u64() expiration.as_u64()
}; };
// If the expiration time is less than our minimum expiration time or greater than the maximum time, consider this watch cancelled // If the expiration time is less than our minimum expiration time consider this watch cancelled
if owvresult.expiration_ts.as_u64() < min_expiration_ts let mut expiration_ts = owvresult.expiration_ts;
|| owvresult.expiration_ts.as_u64() > max_expiration_ts if expiration_ts.as_u64() < min_expiration_ts {
{
// Don't set the watch so we ignore any stray valuechanged messages
return Ok(Timestamp::new(0)); return Ok(Timestamp::new(0));
} }
// If the expiration time is greated than our maximum expiration time, clamp our local watch so we ignore extra valuechanged messages
if expiration_ts.as_u64() > max_expiration_ts {
expiration_ts = Timestamp::new(max_expiration_ts);
}
// If we requested a cancellation, then consider this watch cancelled // If we requested a cancellation, then consider this watch cancelled
if count == 0 { if count == 0 {
return Ok(Timestamp::new(0)); return Ok(Timestamp::new(0));
@ -657,7 +660,7 @@ impl StorageManager {
// Keep a record of the watch // Keep a record of the watch
opened_record.set_active_watch(ActiveWatch { opened_record.set_active_watch(ActiveWatch {
expiration_ts: owvresult.expiration_ts, expiration_ts,
watch_node: owvresult.watch_node, watch_node: owvresult.watch_node,
opt_value_changed_route: owvresult.opt_value_changed_route, opt_value_changed_route: owvresult.opt_value_changed_route,
subkeys, subkeys,

View File

@ -760,9 +760,12 @@ where
let cur_ts = get_timestamp(); let cur_ts = get_timestamp();
let max_ts = cur_ts + self.limits.max_watch_expiration.as_u64(); let max_ts = cur_ts + self.limits.max_watch_expiration.as_u64();
let min_ts = cur_ts + self.limits.min_watch_expiration.as_u64(); let min_ts = cur_ts + self.limits.min_watch_expiration.as_u64();
if expiration.as_u64() == 0 {
if expiration.as_u64() == 0 || expiration.as_u64() > max_ts {
// Clamp expiration max time (or set zero expiration to max)
expiration = Timestamp::new(max_ts); expiration = Timestamp::new(max_ts);
} else if expiration.as_u64() < min_ts || expiration.as_u64() > max_ts { } else if expiration.as_u64() < min_ts {
// Don't add watches with too low of an expiration time
return Ok(None); return Ok(None);
} }