fix: keep OpenRPC ServerHandle alive to prevent server shutdown

The ServerHandle was being dropped immediately after spawning, causing the
OpenRPC server to shut down. Now we properly await handle.stopped() to keep
the server running.
This commit is contained in:
Timur Gordon
2025-10-27 14:34:22 +01:00
parent 98b2718d58
commit a47157aa71
3 changed files with 37 additions and 7 deletions

View File

@@ -133,8 +133,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
tokio::spawn(async move { tokio::spawn(async move {
info!("Starting OpenRPC server on {}:{}", bind_addr, port); info!("Starting OpenRPC server on {}:{}", bind_addr, port);
if let Err(e) = start_http_openrpc_server(supervisor_arc, &bind_addr, port).await { match start_http_openrpc_server(supervisor_arc, &bind_addr, port).await {
error!("OpenRPC server error: {}", e); Ok(handle) => {
info!("OpenRPC server started successfully");
// Keep the server running by holding the handle
handle.stopped().await;
error!("OpenRPC server stopped unexpectedly");
}
Err(e) => {
error!("OpenRPC server error: {}", e);
}
} }
}); });

View File

@@ -18,6 +18,14 @@ This example demonstrates the complete workflow of using Hero Supervisor with OS
## Prerequisites ## Prerequisites
**IMPORTANT: Redis must be running before starting this example!**
```bash
# Start Redis (if not already running)
redis-server
```
Other requirements:
- Redis server running on `localhost:6379` - Redis server running on `localhost:6379`
- Rust toolchain installed - Rust toolchain installed
- Both `supervisor` and `runner_rust` crates available - Both `supervisor` and `runner_rust` crates available

View File

@@ -41,15 +41,29 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut supervisor = supervisor_binary.command() let mut supervisor = supervisor_binary.command()
.arg("--redis-url") .arg("--redis-url")
.arg("redis://localhost:6379") .arg("redis://localhost:6379")
.arg("--openrpc") .arg("--port")
.arg("--openrpc-port")
.arg("3030") .arg("3030")
.stdout(Stdio::piped()) .arg("--admin-secret")
.stderr(Stdio::piped()) .arg("admin_secret")
.arg("--user-secret")
.arg("user_secret")
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()?; .spawn()?;
println!("✅ Supervisor started on port 3030"); println!("✅ Supervisor started on port 3030");
sleep(Duration::from_secs(2)).await; println!("⏳ Waiting for supervisor to initialize...");
sleep(Duration::from_secs(5)).await;
// Check if supervisor is still running
match supervisor.try_wait()? {
Some(status) => {
return Err(format!("Supervisor exited early with status: {}", status).into());
}
None => {
println!("✅ Supervisor is running");
}
}
// ======================================================================== // ========================================================================
// STEP 2: Build OSIRIS runner // STEP 2: Build OSIRIS runner