(
state: &Arc<ServerState>,
sandbox_id: &str,
session_id: &str,
tx: &mpsc::Sender<GatewayMessage>,
inbound: &mut tonic::Streaming<SupervisorMessage>,
mut shutdown_rx: oneshot::
| 711 | } |
| 712 | |
| 713 | async fn run_session_loop( |
| 714 | state: &Arc<ServerState>, |
| 715 | sandbox_id: &str, |
| 716 | session_id: &str, |
| 717 | tx: &mpsc::Sender<GatewayMessage>, |
| 718 | inbound: &mut tonic::Streaming<SupervisorMessage>, |
| 719 | mut shutdown_rx: oneshot::Receiver<()>, |
| 720 | ) { |
| 721 | let heartbeat_interval = Duration::from_secs(u64::from(HEARTBEAT_INTERVAL_SECS)); |
| 722 | let mut heartbeat_timer = tokio::time::interval(heartbeat_interval); |
| 723 | // Skip the first immediate tick. |
| 724 | heartbeat_timer.tick().await; |
| 725 | |
| 726 | loop { |
| 727 | tokio::select! { |
| 728 | _ = &mut shutdown_rx => { |
| 729 | info!(sandbox_id = %sandbox_id, session_id = %session_id, "supervisor session: superseded by reconnect, shutting down"); |
| 730 | break; |
| 731 | } |
| 732 | msg = inbound.message() => { |
| 733 | match msg { |
| 734 | Ok(Some(msg)) => { |
| 735 | handle_supervisor_message(state, sandbox_id, session_id, msg); |
| 736 | } |
| 737 | Ok(None) => { |
| 738 | info!(sandbox_id = %sandbox_id, session_id = %session_id, "supervisor session: stream closed by supervisor"); |
| 739 | break; |
| 740 | } |
| 741 | Err(e) => { |
| 742 | warn!(sandbox_id = %sandbox_id, session_id = %session_id, error = %e, "supervisor session: stream error"); |
| 743 | break; |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | _ = heartbeat_timer.tick() => { |
| 748 | let hb = GatewayMessage { |
| 749 | payload: Some(gateway_message::Payload::Heartbeat( |
| 750 | openshell_core::proto::GatewayHeartbeat {}, |
| 751 | )), |
| 752 | }; |
| 753 | if tx.send(hb).await.is_err() { |
| 754 | info!(sandbox_id = %sandbox_id, session_id = %session_id, "supervisor session: outbound channel closed"); |
| 755 | break; |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | fn handle_supervisor_message( |
| 763 | state: &Arc<ServerState>, |
no outgoing calls
no test coverage detected