Skip to content

Commit d184571

Browse files
feat(streams)!: enforce forwarding and relay lifecycle
Preserve directional EOF across ForwardTcp, RelayStream, and PeerRelay. Negotiate response FIN support, propagate downstream legacy limitations, and preserve typed aborts through owned bridges and session-scoped relays. Update CLI forwarding, generated bindings, documentation, and regressions. BREAKING CHANGE: malformed post-init frames now fail explicitly, relay I/O and trailer failures reach callers, and RelayClose actively aborts its owned operation. Negotiated streams wait for both directions to finish. Wire additions remain capability-gated; existing SDK Close meanings stay unchanged. Flag these behavioral changes for release review, particularly if the merge occurs after September 25, 2026. Validation: lifecycle regressions, gateway and supervisor tests, Python and TypeScript tests, and Go SDK CI passed. Full-suite validation is blocked by missing e2fsprogs for five VM tests. Docker E2E is blocked by read-only BuildKit storage before fixture creation. Refs NVIDIA#3056 Signed-off-by: Varsha Prasad Narsing <[email protected]>
1 parent 9912d21 commit d184571

13 files changed

Lines changed: 1292 additions & 547 deletions

File tree

‎crates/openshell-cli/src/run.rs‎

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,6 @@ async fn forward_one_tcp_connection(
22322232
service_id: String,
22332233
authorization_token: String,
22342234
) -> std::result::Result<(), ForwardTcpConnectionError> {
2235-
use tokio::io::{AsyncReadExt, AsyncWriteExt};
22362235
use tokio_stream::wrappers::ReceiverStream;
22372236

22382237
let (tx, rx) = tokio::sync::mpsc::channel::<TcpForwardFrame>(16);
@@ -2247,13 +2246,14 @@ async fn forward_one_tcp_connection(
22472246
port: u32::from(target_port),
22482247
})),
22492248
authorization_token,
2249+
capabilities: openshell_core::stream_lifecycle::capabilities(),
22502250
},
22512251
)),
22522252
})
22532253
.await
22542254
.map_err(|_| ForwardTcpConnectionError::transient("failed to initialize forward stream"))?;
22552255

2256-
let mut response = match client.forward_tcp(ReceiverStream::new(rx)).await {
2256+
let response = match client.forward_tcp(ReceiverStream::new(rx)).await {
22572257
Ok(response) => response.into_inner(),
22582258
Err(status) => {
22592259
let err = ForwardTcpConnectionError::from_status(status);
@@ -2262,51 +2262,10 @@ async fn forward_one_tcp_connection(
22622262
}
22632263
};
22642264

2265-
let (mut local_read, mut local_write) = socket.into_split();
2266-
2267-
let to_gateway = tokio::spawn(async move {
2268-
let mut buf = vec![0u8; 64 * 1024];
2269-
loop {
2270-
let n = local_read.read(&mut buf).await?;
2271-
if n == 0 {
2272-
break;
2273-
}
2274-
if tx
2275-
.send(TcpForwardFrame {
2276-
payload: Some(openshell_core::proto::tcp_forward_frame::Payload::Data(
2277-
buf[..n].to_vec(),
2278-
)),
2279-
})
2280-
.await
2281-
.is_err()
2282-
{
2283-
break;
2284-
}
2285-
}
2286-
Ok::<(), std::io::Error>(())
2287-
});
2288-
2289-
while let Some(frame) = response
2290-
.message()
2265+
let (local_read, local_write) = socket.into_split();
2266+
openshell_core::stream_lifecycle::client(response, local_read, local_write, tx, true)
22912267
.await
2292-
.map_err(ForwardTcpConnectionError::from_status)?
2293-
{
2294-
let Some(openshell_core::proto::tcp_forward_frame::Payload::Data(data)) = frame.payload
2295-
else {
2296-
continue;
2297-
};
2298-
if data.is_empty() {
2299-
continue;
2300-
}
2301-
local_write
2302-
.write_all(&data)
2303-
.await
2304-
.map_err(|err| ForwardTcpConnectionError::transient(err.to_string()))?;
2305-
}
2306-
2307-
let _ = local_write.shutdown().await;
2308-
to_gateway.abort();
2309-
Ok(())
2268+
.map_err(ForwardTcpConnectionError::from_status)
23102269
}
23112270

23122271
async fn drain_and_shutdown_local_socket(mut socket: tokio::net::TcpStream) {

‎crates/openshell-cli/src/ssh.rs‎

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,64 +1914,28 @@ pub async fn sandbox_ssh_proxy(
19141914
service_id: format!("ssh-proxy:{sandbox_name}"),
19151915
target: Some(tcp_forward_init::Target::Ssh(SshRelayTarget {})),
19161916
authorization_token: token.to_string(),
1917+
capabilities: Vec::new(),
19171918
},
19181919
)),
19191920
})
19201921
.await
19211922
.map_err(|_| miette::miette!("failed to initialize SSH forward stream"))?;
19221923

1923-
let mut response = client
1924+
let response = client
19241925
.forward_tcp(ReceiverStream::new(rx))
19251926
.await
19261927
.into_diagnostic()?
19271928
.into_inner();
19281929

1929-
let stdin = tokio::io::stdin();
1930-
let stdout = tokio::io::stdout();
1931-
1932-
let to_remote = tokio::spawn(async move {
1933-
let mut stdin = stdin;
1934-
let mut buf = vec![0u8; 64 * 1024];
1935-
while let Ok(n) = stdin.read(&mut buf).await {
1936-
if n == 0 {
1937-
break;
1938-
}
1939-
if tx
1940-
.send(TcpForwardFrame {
1941-
payload: Some(openshell_core::proto::tcp_forward_frame::Payload::Data(
1942-
buf[..n].to_vec(),
1943-
)),
1944-
})
1945-
.await
1946-
.is_err()
1947-
{
1948-
break;
1949-
}
1950-
}
1951-
});
1952-
let from_remote = tokio::spawn(async move {
1953-
let mut stdout = stdout;
1954-
loop {
1955-
let Ok(Some(frame)) = response.message().await else {
1956-
break;
1957-
};
1958-
let Some(openshell_core::proto::tcp_forward_frame::Payload::Data(data)) = frame.payload
1959-
else {
1960-
continue;
1961-
};
1962-
if data.is_empty() {
1963-
continue;
1964-
}
1965-
if stdout.write_all(&data).await.is_err() {
1966-
break;
1967-
}
1968-
let _ = stdout.flush().await;
1969-
}
1970-
});
1971-
let _ = from_remote.await;
1972-
to_remote.abort();
1973-
1974-
Ok(())
1930+
openshell_core::stream_lifecycle::client(
1931+
response,
1932+
tokio::io::stdin(),
1933+
tokio::io::stdout(),
1934+
tx,
1935+
false,
1936+
)
1937+
.await
1938+
.into_diagnostic()
19751939
}
19761940

19771941
fn grpc_server_from_ssh_gateway_url(gateway_url: &str) -> Result<String> {

‎crates/openshell-core/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub mod secrets;
5454
pub mod settings;
5555
pub mod shell;
5656
pub mod spiffe;
57+
pub mod stream_lifecycle;
5758
pub mod telemetry;
5859
pub mod time;
5960
pub mod transport_errors;

0 commit comments

Comments
 (0)