Skip to content

Commit 026a6ce

Browse files
committed
fix(rivetkit-core): don't install tokio::signal::ctrl_c() handler inside serve_with_config
1 parent 7377471 commit 026a6ce

5 files changed

Lines changed: 22 additions & 18 deletions

File tree

rivetkit-rust/packages/rivetkit-core/examples/counter.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,8 @@ fn counter_factory() -> ActorFactory {
9999
async fn main() -> Result<()> {
100100
let mut registry = CoreRegistry::new();
101101
registry.register("counter", counter_factory());
102-
registry.serve().await
102+
tokio::select! {
103+
res = registry.serve() => res,
104+
_ = tokio::signal::ctrl_c() => Ok(()),
105+
}
103106
}

rivetkit-rust/packages/rivetkit-core/src/engine_process.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ impl EngineProcessManager {
6969
.env("RIVET__METRICS__PORT", metrics_port.to_string())
7070
.env("RIVET__FILE_SYSTEM__PATH", &db_path)
7171
.stdout(Stdio::piped())
72-
.stderr(Stdio::piped());
72+
.stderr(Stdio::piped())
73+
.kill_on_drop(true);
7374

7475
let mut child = command
7576
.spawn()

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ impl CoreRegistry {
416416

417417
pub async fn serve_with_config(self, config: ServeConfig) -> Result<()> {
418418
let dispatcher = self.into_dispatcher(&config);
419-
let mut engine_process = match config.engine_binary_path.as_ref() {
419+
let _engine_process = match config.engine_binary_path.as_ref() {
420420
Some(binary_path) => {
421421
Some(EngineProcessManager::start(binary_path, &config.endpoint).await?)
422422
}
@@ -427,7 +427,7 @@ impl CoreRegistry {
427427
dispatcher: dispatcher.clone(),
428428
});
429429

430-
let handle = start_envoy(rivet_envoy_client::config::EnvoyConfig {
430+
let _handle = start_envoy(rivet_envoy_client::config::EnvoyConfig {
431431
version: config.version,
432432
endpoint: config.endpoint,
433433
token: config.token,
@@ -441,18 +441,12 @@ impl CoreRegistry {
441441
})
442442
.await;
443443

444-
let shutdown_signal = tokio::signal::ctrl_c()
445-
.await
446-
.context("wait for registry shutdown signal");
447-
handle.shutdown(false);
448-
449-
if let Some(engine_process) = engine_process.take() {
450-
engine_process.shutdown().await?;
451-
}
452-
453-
shutdown_signal?;
454-
455-
Ok(())
444+
// Do not install `tokio::signal::ctrl_c()` here. It calls
445+
// `sigaction(SIGINT, ...)` at the POSIX level, which overrides the
446+
// host's default SIGINT handling when rivetkit-core is embedded in
447+
// Node via NAPI and leaves the host process unable to exit. Callers
448+
// drive shutdown themselves by dropping the task.
449+
std::future::pending::<Result<()>>().await
456450
}
457451

458452
fn into_dispatcher(self, config: &ServeConfig) -> Arc<RegistryDispatcher> {

rivetkit-rust/packages/rivetkit/examples/chat.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,8 @@ async fn save_chat_state(ctx: &Ctx<Chat>, state: &ChatState) -> Result<()> {
106106
async fn main() -> Result<()> {
107107
let mut registry = Registry::new();
108108
registry.register::<Chat, _, _>("chat", run);
109-
registry.serve().await
109+
tokio::select! {
110+
res = registry.serve() => res,
111+
_ = tokio::signal::ctrl_c() => Ok(()),
112+
}
110113
}

rivetkit-rust/packages/rivetkit/examples/counter.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,8 @@ async fn main() -> Result<()> {
105105
.action("increment", Counter::increment)
106106
.action("get_count", Counter::get_count)
107107
.done();
108-
registry.serve().await
108+
tokio::select! {
109+
res = registry.serve() => res,
110+
_ = tokio::signal::ctrl_c() => Ok(()),
111+
}
109112
}

0 commit comments

Comments
 (0)