Skip to content

Commit e5ca471

Browse files
MasterPtatoNathanFlurry
authored andcommitted
fix(guard): dont send open msg for hibernating ws, hibernating ws keepalive
1 parent 4039392 commit e5ca471

File tree

30 files changed

+1982
-460
lines changed

30 files changed

+1982
-460
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/packages/cache-purge/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub async fn start(config: rivet_config::Config, pools: rivet_pools::Pools) -> R
99
let ups = pools.ups()?;
1010
let mut sub = ups.subscribe(CACHE_PURGE_TOPIC).await?;
1111

12-
tracing::info!(subject=?CACHE_PURGE_TOPIC, "subscribed to cache purge updates");
12+
tracing::debug!(subject=?CACHE_PURGE_TOPIC, "subscribed to cache purge updates");
1313

1414
// Get cache instance
1515
let cache = rivet_cache::CacheInner::from_env(&config, pools)?;

engine/packages/config/src/config/pegboard.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ pub struct Pegboard {
5050
///
5151
/// **Experimental**
5252
pub runner_lost_threshold: Option<i64>,
53+
/// How long after last ping before considering a hibernating request disconnected.
54+
///
55+
/// Unit is in milliseconds.
56+
///
57+
/// **Experimental**
58+
pub hibernating_request_eligible_threshold: Option<i64>,
5359
}
5460

5561
impl Pegboard {
@@ -80,4 +86,9 @@ impl Pegboard {
8086
pub fn runner_lost_threshold(&self) -> i64 {
8187
self.runner_lost_threshold.unwrap_or(15_000)
8288
}
89+
90+
pub fn hibernating_request_eligible_threshold(&self) -> i64 {
91+
self.hibernating_request_eligible_threshold
92+
.unwrap_or(90_000)
93+
}
8394
}

engine/packages/gasoline/src/db/kv/keys/worker.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use std::result::Result::Ok;
2-
3-
use anyhow::*;
1+
use anyhow::Result;
42
use rivet_util::Id;
53
use universaldb::prelude::*;
64

engine/packages/guard-core/src/custom_serve.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ pub trait CustomServeTrait: Send + Sync {
3434
_request_context: &mut RequestContext,
3535
// Identifies the websocket across retries.
3636
_unique_request_id: Uuid,
37+
// True if this websocket is reconnecting after hibernation.
38+
_after_hibernation: bool,
3739
) -> Result<Option<CloseFrame>> {
3840
bail!("service does not support websockets");
3941
}
@@ -42,6 +44,7 @@ pub trait CustomServeTrait: Send + Sync {
4244
async fn handle_websocket_hibernation(
4345
&self,
4446
_websocket: WebSocketHandle,
47+
_unique_request_id: Uuid,
4548
) -> Result<HibernationResult> {
4649
bail!("service does not support websocket hibernation");
4750
}

engine/packages/guard-core/src/proxy_service.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,7 @@ impl ProxyService {
18451845
async move {
18461846
let request_id = Uuid::new_v4();
18471847
let mut ws_hibernation_close = false;
1848+
let mut after_hibernation = false;
18481849
let mut attempts = 0u32;
18491850

18501851
let ws_handle = WebSocketHandle::new(client_ws)
@@ -1859,6 +1860,7 @@ impl ProxyService {
18591860
&req_path,
18601861
&mut request_context,
18611862
request_id,
1863+
after_hibernation,
18621864
)
18631865
.await
18641866
{
@@ -1926,9 +1928,14 @@ impl ProxyService {
19261928
// - the gateway will continue reading messages from the client ws
19271929
// (starting with the message that caused the hibernation to end)
19281930
let res = handler
1929-
.handle_websocket_hibernation(ws_handle.clone())
1931+
.handle_websocket_hibernation(
1932+
ws_handle.clone(),
1933+
request_id,
1934+
)
19301935
.await?;
19311936

1937+
after_hibernation = true;
1938+
19321939
// Despite receiving a close frame from the client during hibernation
19331940
// we are going to reconnect to the actor so that it knows the
19341941
// connection has closed

engine/packages/guard-core/tests/custom_serve.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl CustomServeTrait for TestCustomServe {
7272
_path: &str,
7373
_request_context: &mut RequestContext,
7474
_unique_request_id: Uuid,
75+
_after_hibernation: bool,
7576
) -> Result<Option<CloseFrame>> {
7677
// Track this WebSocket call
7778
self.tracker
@@ -115,6 +116,7 @@ impl CustomServeTrait for TestCustomServe {
115116
async fn handle_websocket_hibernation(
116117
&self,
117118
_websocket: WebSocketHandle,
119+
_unique_request_id: Uuid,
118120
) -> Result<HibernationResult> {
119121
// Track this WebSocket call
120122
self.tracker

0 commit comments

Comments
 (0)