Skip to content

Commit 6c170d1

Browse files
committed
fix(rivetkit): isolate engine envoys and propagate startup failures
1 parent 2b872b3 commit 6c170d1

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

engine/sdks/rust/envoy-client/src/envoy.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ impl EnvoyContext {
135135

136136
pub async fn start_envoy(config: EnvoyConfig) -> EnvoyHandle {
137137
let handle = start_envoy_sync(config);
138-
handle.started().await;
138+
handle
139+
.started()
140+
.await
141+
.expect("envoy failed to start before returning handle");
139142
handle
140143
}
141144

engine/sdks/rust/envoy-client/src/handle.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ impl EnvoyHandle {
3333
&self.shared.envoy_key
3434
}
3535

36-
pub async fn started(&self) {
37-
let _ = self.started_rx.clone().changed().await;
36+
pub async fn started(&self) -> anyhow::Result<()> {
37+
self.started_rx
38+
.clone()
39+
.changed()
40+
.await
41+
.map_err(|_| anyhow::anyhow!("envoy stopped before startup completed"))?;
42+
Ok(())
3843
}
3944

4045
pub fn sleep_actor(&self, actor_id: String, generation: Option<u32>) {
@@ -310,7 +315,7 @@ impl EnvoyHandle {
310315
}
311316

312317
// Wait for envoy to be started before injecting
313-
self.started().await;
318+
self.started().await?;
314319

315320
tracing::debug!(
316321
data = crate::stringify::stringify_to_envoy(&message),

rivetkit-typescript/packages/rivetkit-native/src/envoy_handle.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ impl JsEnvoyHandle {
5858
self.runtime
5959
.spawn(async move { handle.started().await })
6060
.await
61+
.map_err(|e| napi::Error::from_reason(e.to_string()))?
6162
.map_err(|e| napi::Error::from_reason(e.to_string()))
6263
}
6364

rivetkit-typescript/packages/rivetkit/src/drivers/engine/actor-driver.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export class EngineActorDriver implements ActorDriver {
185185
token: config.token,
186186
namespace: config.namespace,
187187
poolName: config.envoy.poolName,
188+
notGlobal: true,
188189
metadata: {
189190
rivetkit: { version: VERSION },
190191
},
@@ -211,9 +212,14 @@ export class EngineActorDriver implements ActorDriver {
211212

212213
this.#envoy = envoy;
213214

214-
envoy.started().then(() => {
215-
this.#envoyStarted.resolve();
216-
});
215+
envoy.started().then(
216+
() => {
217+
this.#envoyStarted.resolve();
218+
},
219+
(error) => {
220+
this.#envoyStarted.reject(error);
221+
},
222+
);
217223

218224
logger().debug({
219225
msg: "envoy client started",

0 commit comments

Comments
 (0)