Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion engine/sdks/rust/envoy-client/src/envoy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ impl EnvoyContext {

pub async fn start_envoy(config: EnvoyConfig) -> EnvoyHandle {
let handle = start_envoy_sync(config);
handle.started().await;
handle
.started()
.await
.expect("envoy failed to start before returning handle");
handle
}

Expand Down
11 changes: 8 additions & 3 deletions engine/sdks/rust/envoy-client/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ impl EnvoyHandle {
&self.shared.envoy_key
}

pub async fn started(&self) {
let _ = self.started_rx.clone().changed().await;
pub async fn started(&self) -> anyhow::Result<()> {
self.started_rx
.clone()
.changed()
.await
.map_err(|_| anyhow::anyhow!("envoy stopped before startup completed"))?;
Ok(())
}

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

// Wait for envoy to be started before injecting
self.started().await;
self.started().await?;

tracing::debug!(
data = crate::stringify::stringify_to_envoy(&message),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl JsEnvoyHandle {
self.runtime
.spawn(async move { handle.started().await })
.await
.map_err(|e| napi::Error::from_reason(e.to_string()))?
.map_err(|e| napi::Error::from_reason(e.to_string()))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export class EngineActorDriver implements ActorDriver {
token: config.token,
namespace: config.namespace,
poolName: config.envoy.poolName,
notGlobal: true,
metadata: {
rivetkit: { version: VERSION },
},
Expand All @@ -212,9 +213,14 @@ export class EngineActorDriver implements ActorDriver {

this.#envoy = envoy;

envoy.started().then(() => {
this.#envoyStarted.resolve();
});
envoy.started().then(
() => {
this.#envoyStarted.resolve();
},
(error) => {
this.#envoyStarted.reject(error);
},
);

logger().debug({
msg: "envoy client started",
Expand Down
Loading