Skip to content

Commit 24864b7

Browse files
factorydroidFactory Bot
authored andcommitted
fix(cortex-engine): handle SIGPIPE by detecting closed event channel
Fixes bounty issue #1525 When cortex run is piped to a command that closes the pipe (e.g., head -n 1), the session event channel could return a Closed error. Previously this was ignored, causing the session to keep running. Now we detect TrySendError::Closed and properly shut down the session.
1 parent 7a104aa commit 24864b7

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

cortex-engine/src/session.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,8 +1374,21 @@ impl Session {
13741374
let _ = recorder.record_event(&event);
13751375
}
13761376

1377-
// Non-blocking send - never wait
1378-
let _ = self.event_tx.try_send(event);
1377+
// Non-blocking send
1378+
// If the channel is closed (receiver dropped), we should stop the session
1379+
match self.event_tx.try_send(event) {
1380+
Ok(_) => {}
1381+
Err(async_channel::TrySendError::Full(_)) => {
1382+
// Channel full - dropping event (shouldn't happen with unbounded)
1383+
tracing::warn!("Event channel full, dropping event");
1384+
}
1385+
Err(async_channel::TrySendError::Closed(_)) => {
1386+
// Channel closed - receiver is gone (e.g. pipe broken)
1387+
tracing::info!("Event channel closed, stopping session");
1388+
self.running = false;
1389+
self.cancelled.store(true, Ordering::SeqCst);
1390+
}
1391+
}
13791392
}
13801393

13811394
/// Resume a session from a rollout file.

0 commit comments

Comments
 (0)