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

Method wait_for_session

crates/openshell-server/src/supervisor_session.rs:172–190  ·  view source on GitHub ↗

Look up the sender for a supervisor session, waiting up to `timeout` for it to appear if absent. Uses exponential backoff (100ms → 2s) while polling the sessions map.

(
        &self,
        sandbox_id: &str,
        timeout: Duration,
    )

Source from the content-addressed store, hash-verified

170 ///
171 /// Uses exponential backoff (100ms → 2s) while polling the sessions map.
172 async fn wait_for_session(
173 &self,
174 sandbox_id: &str,
175 timeout: Duration,
176 ) -> Result<mpsc::Sender<GatewayMessage>, Status> {
177 let deadline = Instant::now() + timeout;
178 let mut backoff = SESSION_WAIT_INITIAL_BACKOFF;
179
180 loop {
181 if let Some(tx) = self.lookup_session(sandbox_id) {
182 return Ok(tx);
183 }
184 if Instant::now() + backoff > deadline {
185 return Err(Status::unavailable("supervisor session not connected"));
186 }
187 tokio::time::sleep(backoff).await;
188 backoff = (backoff * 2).min(SESSION_WAIT_MAX_BACKOFF);
189 }
190 }
191
192 fn lookup_session(&self, sandbox_id: &str) -> Option<mpsc::Sender<GatewayMessage>> {
193 self.sessions

Callers 1

Calls 1

lookup_sessionMethod · 0.80

Tested by

no test coverage detected