Skip to content

Commit f2f82a8

Browse files
committed
fix(envoy-client): dont abort drain after 20s
1 parent 40c3589 commit f2f82a8

8 files changed

Lines changed: 67 additions & 33 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub struct Pegboard {
159159

160160
impl Pegboard {
161161
pub fn base_retry_timeout(&self) -> usize {
162-
self.base_retry_timeout.unwrap_or(2000)
162+
self.base_retry_timeout.unwrap_or(2_000)
163163
}
164164

165165
pub fn actor_allocation_threshold(&self) -> i64 {
@@ -177,7 +177,7 @@ impl Pegboard {
177177
}
178178

179179
pub fn actor_retry_duration_threshold(&self) -> i64 {
180-
self.actor_retry_duration_threshold.unwrap_or(300_000)
180+
self.actor_retry_duration_threshold.unwrap_or(5 * 60 * 1000)
181181
}
182182

183183
pub fn retry_reset_duration(&self) -> i64 {
@@ -202,7 +202,7 @@ impl Pegboard {
202202
}
203203

204204
pub fn serverless_base_retry_timeout(&self) -> usize {
205-
self.serverless_base_retry_timeout.unwrap_or(2000)
205+
self.serverless_base_retry_timeout.unwrap_or(2_000)
206206
}
207207

208208
pub fn serverless_retry_reset_duration(&self) -> i64 {
@@ -237,7 +237,7 @@ impl Pegboard {
237237

238238
pub fn gateway_response_start_timeout_ms(&self) -> u64 {
239239
self.gateway_response_start_timeout_ms
240-
.unwrap_or(5 * 60 * 1000) // 5 minutes
240+
.unwrap_or(5 * 60 * 1000)
241241
}
242242

243243
pub fn gateway_update_ping_interval_ms(&self) -> u64 {

examples/kitchen-sink/Dockerfile.local

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

examples/kitchen-sink/package.json

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

examples/kitchen-sink/src/index.ts

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/kitchen-sink/src/mode.ts

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

examples/kitchen-sink/src/server.ts

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rivetkit-rust/packages/rivetkit-core/src/registry/mod.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ mod websocket;
7474
use inspector::build_actor_inspector;
7575
use websocket::is_actor_connect_path;
7676

77-
/// Bound on `handle.shutdown_and_wait` inside `serve_with_config` teardown.
78-
/// Protects against indefinite hangs if the envoy reconnect loop is stuck;
79-
/// the TS/outer-host grace period is the ultimate backstop.
80-
const SHUTDOWN_DRAIN_TIMEOUT: Duration = Duration::from_secs(20);
81-
8277
#[derive(Debug, Default)]
8378
pub struct CoreRegistry {
8479
factories: HashMap<String, Arc<ActorFactory>>,
@@ -530,10 +525,22 @@ impl CoreRegistry {
530525
// trip the `shutdown` token instead.
531526
shutdown.cancelled().await;
532527

528+
// TODO: Move into envoy-client since timing out has to do with protocol compliance
529+
// Read threshold from protocol metadata, fall back to 30 min
530+
let stop_threshold = handle
531+
.get_protocol_metadata
532+
.await
533+
.map(|x| x.actor_stop_threshold)
534+
.unwrap_or(30 * 60 * 1000);
533535
// Bounded drain. If envoy cannot reach the engine (reconnect loop stuck),
534536
// we fall back to immediate `Stop` rather than hanging indefinitely.
535537
// The outer host (TS signal handler / Rust binary) is the backstop.
536-
match timeout(SHUTDOWN_DRAIN_TIMEOUT, handle.shutdown_and_wait(false)).await {
538+
match timeout(
539+
Duration::from_millis(SHUTDOWN_DRAIN_TIMEOUT as u64),
540+
handle.shutdown_and_wait(false),
541+
)
542+
.await
543+
{
537544
Ok(()) => {}
538545
Err(_) => {
539546
tracing::warn!("envoy shutdown drain exceeded timeout; forcing immediate stop");
@@ -718,11 +725,8 @@ impl RegistryDispatcher {
718725

719726
let (start_tx, start_rx) = oneshot::channel();
720727
let result: Result<Arc<ActorTaskHandle>> = async {
721-
try_send_lifecycle_command(
722-
&lifecycle_tx,
723-
LifecycleCommand::Start { reply: start_tx },
724-
)
725-
.context("send actor task start command")?;
728+
try_send_lifecycle_command(&lifecycle_tx, LifecycleCommand::Start { reply: start_tx })
729+
.context("send actor task start command")?;
726730
start_rx
727731
.await
728732
.context("receive actor task start reply")?

rivetkit-typescript/packages/rivetkit-napi/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export declare class CoreRegistry {
314314
* Idempotent. Safe to call when neither mode has been activated.
315315
* Does not block on the `serve()` future; TS awaits that promise
316316
* separately to avoid re-entrancy.
317-
*/
317+
*/
318318
shutdown(): Promise<void>
319319
health(): Promise<JsRegistryRouteResponse>
320320
metadata(): JsRegistryRouteResponse

0 commit comments

Comments
 (0)