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:
@@ -133,9 +133,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
tokio::spawn(async move {
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Give the server a moment to start
|
||||
|
||||
@@ -18,6 +18,14 @@ This example demonstrates the complete workflow of using Hero Supervisor with OS
|
||||
|
||||
## 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`
|
||||
- Rust toolchain installed
|
||||
- Both `supervisor` and `runner_rust` crates available
|
||||
|
||||
@@ -41,15 +41,29 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut supervisor = supervisor_binary.command()
|
||||
.arg("--redis-url")
|
||||
.arg("redis://localhost:6379")
|
||||
.arg("--openrpc")
|
||||
.arg("--openrpc-port")
|
||||
.arg("--port")
|
||||
.arg("3030")
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.arg("--admin-secret")
|
||||
.arg("admin_secret")
|
||||
.arg("--user-secret")
|
||||
.arg("user_secret")
|
||||
.stdout(Stdio::inherit())
|
||||
.stderr(Stdio::inherit())
|
||||
.spawn()?;
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user