Skip to content

Commit f5cac12

Browse files
authored
fix(process-daemon): block subscriptions instead of polling (#59698)
1 parent 5f394f6 commit f5cac12

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎packages/process-daemon/src/daemon/server.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ fn stream_subscription(
288288
Ok(event) => event,
289289
Err(_) => break Ok(()),
290290
},
291-
default(Duration::from_millis(100)) => continue,
292291
};
293292
let response = match event {
294293
StreamEvent::Output { start, end, bytes } => {

‎packages/process-daemon/tests/ownership.rs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,37 @@ fn subscription_delivers_final_exit_frame_before_closing() {
277277
daemon.wait();
278278
}
279279

280+
#[test]
281+
fn shutdown_ends_an_idle_subscription() {
282+
let mut daemon = Daemon::start();
283+
let (mut owner, response) = daemon.own(None);
284+
assert!(matches!(response, Response::Owned));
285+
let terminal = daemon.terminal("exec cat");
286+
let mut subscription = daemon.connect();
287+
assert!(matches!(
288+
daemon.send(
289+
&mut subscription,
290+
Request::Subscribe {
291+
id: terminal.id,
292+
offset: 0,
293+
attachment_id: "idle-observer".into(),
294+
role: AttachmentRole::Observer,
295+
takeover: false,
296+
}
297+
),
298+
Response::Attached { .. }
299+
));
300+
// The subscription is blocked with no output; shutdown must still end it.
301+
assert!(matches!(
302+
daemon.send(&mut owner, Request::Shutdown),
303+
Response::Ok
304+
));
305+
// The 3s read timeout fails this read if the handler never closes the stream.
306+
subscription.read_to_end(&mut Vec::new()).unwrap();
307+
daemon.wait();
308+
assert_terminal_stopped(&terminal);
309+
}
310+
280311
#[test]
281312
fn handoff_preserves_daemon_and_terminal_and_shutdown_overrides_it() {
282313
let mut daemon = Daemon::start();

0 commit comments

Comments
 (0)