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

Function stream_exec_over_relay

crates/openshell-server/src/grpc/sandbox.rs:1548–1620  ·  view source on GitHub ↗
(
    tx: mpsc::Sender<Result<ExecSandboxEvent, Status>>,
    sandbox_id: &str,
    channel_id: &str,
    relay_stream: tokio::io::DuplexStream,
    command: &str,
    stdin_payload: Vec<u8>,
    time

Source from the content-addressed store, hash-verified

1546/// is bridged to the supervisor's local SSH daemon via `RelayStream`.
1547#[allow(clippy::too_many_arguments)]
1548async fn stream_exec_over_relay(
1549 tx: mpsc::Sender<Result<ExecSandboxEvent, Status>>,
1550 sandbox_id: &str,
1551 channel_id: &str,
1552 relay_stream: tokio::io::DuplexStream,
1553 command: &str,
1554 stdin_payload: Vec<u8>,
1555 timeout_seconds: u32,
1556 request_tty: bool,
1557) -> Result<(), Status> {
1558 let command_preview: String = command.chars().take(120).collect();
1559 info!(
1560 sandbox_id = %sandbox_id,
1561 channel_id = %channel_id,
1562 command_len = command.len(),
1563 stdin_len = stdin_payload.len(),
1564 command_preview = %command_preview,
1565 "ExecSandbox (relay): command started"
1566 );
1567
1568 let (local_proxy_port, proxy_task) = start_single_use_ssh_proxy_over_relay(relay_stream)
1569 .await
1570 .map_err(|e| Status::internal(format!("failed to start relay proxy: {e}")))?;
1571
1572 let exec = run_exec_with_russh(
1573 local_proxy_port,
1574 command,
1575 stdin_payload,
1576 request_tty,
1577 tx.clone(),
1578 );
1579
1580 let exec_result = if timeout_seconds == 0 {
1581 exec.await
1582 } else if let Ok(r) = tokio::time::timeout(
1583 std::time::Duration::from_secs(u64::from(timeout_seconds)),
1584 exec,
1585 )
1586 .await
1587 {
1588 r
1589 } else {
1590 let _ = tx
1591 .send(Ok(ExecSandboxEvent {
1592 payload: Some(openshell_core::proto::exec_sandbox_event::Payload::Exit(
1593 ExecSandboxExit { exit_code: 124 },
1594 )),
1595 }))
1596 .await;
1597 let _ = proxy_task.await;
1598 return Ok(());
1599 };
1600
1601 let exit_code = match exec_result {
1602 Ok(code) => code,
1603 Err(status) => {
1604 let _ = proxy_task.await;
1605 return Err(status);

Callers 1

handle_exec_sandboxFunction · 0.85

Calls 2

run_exec_with_russhFunction · 0.85

Tested by

no test coverage detected