MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / await_relay_stream

Function await_relay_stream

crates/openshell-server/src/grpc/sandbox.rs:884–913  ·  view source on GitHub ↗

Wait for the supervisor's reverse CONNECT to deliver a relay stream. Returns `Some(stream)` on success. On any failure the error is sent on `tx` and `None` is returned; the caller should then `return` immediately.

(
    relay_rx: oneshot::Receiver<Result<tokio::io::DuplexStream, Status>>,
    tx: &mpsc::Sender<Result<T, Status>>,
    sandbox_id: &str,
    channel_id: &str,
    context: &str,
)

Source from the content-addressed store, hash-verified

882/// Returns `Some(stream)` on success. On any failure the error is sent on `tx`
883/// and `None` is returned; the caller should then `return` immediately.
884async fn await_relay_stream<T: Send + 'static>(
885 relay_rx: oneshot::Receiver<Result<tokio::io::DuplexStream, Status>>,
886 tx: &mpsc::Sender<Result<T, Status>>,
887 sandbox_id: &str,
888 channel_id: &str,
889 context: &str,
890) -> Option<tokio::io::DuplexStream> {
891 match tokio::time::timeout(std::time::Duration::from_secs(10), relay_rx).await {
892 Ok(Ok(Ok(stream))) => Some(stream),
893 Ok(Ok(Err(status))) => {
894 warn!(sandbox_id = %sandbox_id, channel_id = %channel_id, error = %status.message(), "{context}: relay target open failed");
895 let _ = tx.send(Err(status)).await;
896 None
897 }
898 Ok(Err(_)) => {
899 warn!(sandbox_id = %sandbox_id, channel_id = %channel_id, "{context}: relay channel dropped");
900 let _ = tx
901 .send(Err(Status::unavailable("relay channel dropped")))
902 .await;
903 None
904 }
905 Err(_) => {
906 warn!(sandbox_id = %sandbox_id, channel_id = %channel_id, "{context}: relay open timed out");
907 let _ = tx
908 .send(Err(Status::deadline_exceeded("relay open timed out")))
909 .await;
910 None
911 }
912 }
913}
914
915pub(super) async fn handle_forward_tcp(
916 state: &Arc<ServerState>,

Callers 3

handle_exec_sandboxFunction · 0.85
handle_forward_tcpFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected