Make unified exec output closure race-safe (#63664)

## Why

The output collector could miss a closure notification while starting its
post-exit wait. It could also see an empty buffer just before the producer
appended its final chunk and closed the stream.

## What changed

Use a dedicated `CancellationToken` to signal when the output producer is
done. The collector samples closure before draining the buffer so that
closure during the drain wakes it for another pass. The streaming watcher
flushes queued chunks when it observes closure, and sandbox denial checks
can proceed immediately when output is already closed.

## Testing

Update the bounded collection test to verify that closure alone wakes
the post-exit collector and that the final bytes survive repeated drains.

GitOrigin-RevId: 4b94a018d784664031f326ec360d27fcf166bbda
This commit is contained in:
jif
2026-11-24 15:53:55 +00:00
committed by copyberry
parent 3781b6c627
commit ebd5c2fddc
5 changed files with 73 additions and 194 deletions
@@ -1,7 +1,6 @@
use codex_protocol::openai_models::CatalogModel; use codex_protocol::openai_models::CatalogModel;
use std::pin::Pin; use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::Ordering;
use tokio::sync::Mutex; use tokio::sync::Mutex;
use tokio::time::Duration; use tokio::time::Duration;
@@ -11,7 +10,6 @@ use tokio::time::Sleep;
use super::SharedPluginMetricsSidecar; use super::SharedPluginMetricsSidecar;
use super::UnifiedExecContext; use super::UnifiedExecContext;
use super::process::OutputBuffers; use super::process::OutputBuffers;
use super::process::OutputHandles;
use super::process::UnifiedExecProcess; use super::process::UnifiedExecProcess;
use super::take_plugin_metrics_sidecar; use super::take_plugin_metrics_sidecar;
use crate::exec::MAX_EXEC_OUTPUT_DELTAS_PER_CALL; use crate::exec::MAX_EXEC_OUTPUT_DELTAS_PER_CALL;
@@ -58,11 +56,7 @@ pub(crate) fn start_streaming_output(process: &UnifiedExecProcess, context: &Uni
let mut receiver = process.output_receiver(); let mut receiver = process.output_receiver();
let output_drained = process.output_drained_notify(); let output_drained = process.output_drained_notify();
let exit_token = process.cancellation_token(); let exit_token = process.cancellation_token();
let OutputHandles { let output_closed = process.output_handles().output_closed.clone();
output_closed,
output_closed_notify,
..
} = process.output_handles().clone();
let emitter = Emitter { let emitter = Emitter {
remaining_deltas: MAX_EXEC_OUTPUT_DELTAS_PER_CALL, remaining_deltas: MAX_EXEC_OUTPUT_DELTAS_PER_CALL,
@@ -80,19 +74,8 @@ pub(crate) fn start_streaming_output(process: &UnifiedExecProcess, context: &Uni
}; };
let mut grace_sleep: Option<Pin<Box<Sleep>>> = None; let mut grace_sleep: Option<Pin<Box<Sleep>>> = None;
let output_closed_notified = output_closed_notify.notified();
tokio::pin!(output_closed_notified);
let mut output_complete = false;
loop { loop {
// Register before checking the atomic so a close between the check
// and the select cannot miss the notification.
output_closed_notified.as_mut().enable();
if grace_sleep.is_some() && output_closed.load(Ordering::Acquire) {
output_complete = true;
break;
}
tokio::select! { tokio::select! {
_ = exit_token.cancelled(), if grace_sleep.is_none() => { _ = exit_token.cancelled(), if grace_sleep.is_none() => {
let deadline = Instant::now() + TRAILING_OUTPUT_GRACE; let deadline = Instant::now() + TRAILING_OUTPUT_GRACE;
@@ -107,20 +90,13 @@ pub(crate) fn start_streaming_output(process: &UnifiedExecProcess, context: &Uni
break; break;
} }
_ = &mut output_closed_notified, if grace_sleep.is_some() => { _ = output_closed.cancelled(), if grace_sleep.is_some() => break,
output_closed_notified.set(output_closed_notify.notified());
}
received = receiver.recv() => { received = receiver.recv() => {
let chunk = match received { let chunk = match received {
Ok(chunk) => chunk, Ok(chunk) => chunk,
Err(RecvError::Lagged(_)) => { Err(RecvError::Lagged(_)) => continue,
continue; Err(RecvError::Closed) => break,
},
Err(RecvError::Closed) => {
output_complete = true;
break;
}
}; };
output.push(chunk).await; output.push(chunk).await;
@@ -128,11 +104,8 @@ pub(crate) fn start_streaming_output(process: &UnifiedExecProcess, context: &Uni
} }
} }
output_complete |= output_closed.load(Ordering::Acquire); // Closure can win the select while the receiver still has queued chunks.
if output_complete { if output_closed.is_cancelled() {
// Output producers publish all chunks before setting output_closed
// with Release ordering, so the Acquire above makes this a final
// safe drain.
loop { loop {
let chunk = match receiver.try_recv() { let chunk = match receiver.try_recv() {
Ok(chunk) => chunk, Ok(chunk) => chunk,
+13 -61
View File
@@ -60,26 +60,14 @@ impl<const MAX_BYTES: usize> OutputBuffers<MAX_BYTES> {
pub(crate) struct OutputHandles<const MAX_BYTES: usize = UNIFIED_EXEC_OUTPUT_MAX_BYTES> { pub(crate) struct OutputHandles<const MAX_BYTES: usize = UNIFIED_EXEC_OUTPUT_MAX_BYTES> {
pub(crate) output_buffer: Arc<Mutex<OutputBuffers<MAX_BYTES>>>, pub(crate) output_buffer: Arc<Mutex<OutputBuffers<MAX_BYTES>>>,
pub(crate) output_notify: Arc<Notify>, pub(crate) output_notify: Arc<Notify>,
pub(crate) output_closed: Arc<AtomicBool>, /// Cancelled once the producer can no longer append or broadcast output.
pub(crate) output_closed_notify: Arc<Notify>, pub(crate) output_closed: CancellationToken,
pub(crate) cancellation_token: CancellationToken, pub(crate) cancellation_token: CancellationToken,
pub(super) drain_policy: OutputDrainPolicy, pub(super) drain_policy: OutputDrainPolicy,
/// The initial exec call returned or was cancelled, so background draining may begin. /// The initial exec call returned or was cancelled, so background draining may begin.
pub(crate) collection_finished: CancellationToken, pub(crate) collection_finished: CancellationToken,
} }
struct OutputTaskGuard {
output_closed: Arc<AtomicBool>,
output_closed_notify: Arc<Notify>,
}
impl Drop for OutputTaskGuard {
fn drop(&mut self) {
self.output_closed.store(true, Ordering::Release);
self.output_closed_notify.notify_waiters();
}
}
/// Controls whether process exit can start the collectors' bounded output drain. /// Controls whether process exit can start the collectors' bounded output drain.
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub(super) enum OutputDrainPolicy { pub(super) enum OutputDrainPolicy {
@@ -133,8 +121,7 @@ impl UnifiedExecProcess {
let output = OutputHandles { let output = OutputHandles {
output_buffer: Arc::new(Mutex::new(OutputBuffers::default())), output_buffer: Arc::new(Mutex::new(OutputBuffers::default())),
output_notify: Arc::new(Notify::new()), output_notify: Arc::new(Notify::new()),
output_closed: Arc::new(AtomicBool::new(false)), output_closed: CancellationToken::new(),
output_closed_notify: Arc::new(Notify::new()),
cancellation_token: CancellationToken::new(), cancellation_token: CancellationToken::new(),
drain_policy, drain_policy,
collection_finished: CancellationToken::new(), collection_finished: CancellationToken::new(),
@@ -307,21 +294,10 @@ impl UnifiedExecProcess {
} }
pub(super) async fn check_for_sandbox_denial(&self) -> Result<(), UnifiedExecError> { pub(super) async fn check_for_sandbox_denial(&self) -> Result<(), UnifiedExecError> {
// A closed output stream cannot provide any more denial context.
if !self.output.output_closed.load(Ordering::Acquire) {
let closed = self.output.output_closed_notify.notified();
tokio::pin!(closed);
closed.as_mut().enable();
// Recheck after registering so closure cannot be lost before we wait.
if !self.output.output_closed.load(Ordering::Acquire) {
let _ = tokio::time::timeout(Duration::from_millis(20), async {
tokio::select! { tokio::select! {
_ = self.output.output_closed.cancelled() => {}
_ = self.output.output_notify.notified() => {} _ = self.output.output_notify.notified() => {}
_ = &mut closed => {} _ = tokio::time::sleep(Duration::from_millis(20)) => {}
}
})
.await;
}
} }
let aggregated = self.snapshot_output().await; let aggregated = self.snapshot_output().await;
@@ -478,7 +454,6 @@ impl UnifiedExecProcess {
output_buffer, output_buffer,
output_notify, output_notify,
output_closed, output_closed,
output_closed_notify,
cancellation_token, cancellation_token,
collection_finished, collection_finished,
.. ..
@@ -486,11 +461,8 @@ impl UnifiedExecProcess {
let process = started.process; let process = started.process;
let mut events = process.subscribe_events(); let mut events = process.subscribe_events();
let mut state_rx = state_tx.subscribe(); let mut state_rx = state_tx.subscribe();
let close_output = output_closed.drop_guard();
tokio::spawn(async move { tokio::spawn(async move {
let _output_task_guard = OutputTaskGuard {
output_closed: Arc::clone(&output_closed),
output_closed_notify: Arc::clone(&output_closed_notify),
};
let drain = async { let drain = async {
collection_finished.cancelled().await; collection_finished.cancelled().await;
let _ = state_rx.wait_for(|state| state.has_exited).await; let _ = state_rx.wait_for(|state| state.has_exited).await;
@@ -519,9 +491,6 @@ impl UnifiedExecProcess {
state_tx.send_modify(|state| { state_tx.send_modify(|state| {
state.failed("exec-server process event stream closed".to_string()); state.failed("exec-server process event stream closed".to_string());
}); });
output_closed.store(true, Ordering::Release);
output_closed_notify.notify_waiters();
cancellation_token.cancel();
break; break;
} }
}; };
@@ -556,9 +525,6 @@ impl UnifiedExecProcess {
Ok(response) => response, Ok(response) => response,
Err(err) => { Err(err) => {
state_tx.send_modify(|state| state.failed(err.to_string())); state_tx.send_modify(|state| state.failed(err.to_string()));
output_closed.store(true, Ordering::Release);
output_closed_notify.notify_waiters();
cancellation_token.cancel();
break; break;
} }
}; };
@@ -582,9 +548,6 @@ impl UnifiedExecProcess {
last_seq = last_seq.max(next_seq.saturating_sub(1)); last_seq = last_seq.max(next_seq.saturating_sub(1));
if let Some(message) = failure { if let Some(message) = failure {
state_tx.send_modify(|state| state.failed(message)); state_tx.send_modify(|state| state.failed(message));
output_closed.store(true, Ordering::Release);
output_closed_notify.notify_waiters();
cancellation_token.cancel();
break; break;
} }
if sandbox_denied || exited { if sandbox_denied || exited {
@@ -595,15 +558,12 @@ impl UnifiedExecProcess {
} }
}); });
} }
if closed || final_drain {
break;
}
if exited && output_drain_policy == OutputDrainPolicy::BoundedAfterExit { if exited && output_drain_policy == OutputDrainPolicy::BoundedAfterExit {
cancellation_token.cancel(); cancellation_token.cancel();
} }
if closed || final_drain {
output_closed.store(true, Ordering::Release);
output_closed_notify.notify_waiters();
cancellation_token.cancel();
break;
}
continue; continue;
} }
@@ -644,26 +604,21 @@ impl UnifiedExecProcess {
if seq <= last_seq { if seq <= last_seq {
continue; continue;
} }
output_closed.store(true, Ordering::Release);
output_closed_notify.notify_waiters();
cancellation_token.cancel();
break; break;
} }
ExecProcessEvent::Failed(message) => { ExecProcessEvent::Failed(message) => {
state_tx.send_modify(|state| state.failed(message)); state_tx.send_modify(|state| state.failed(message));
output_closed.store(true, Ordering::Release);
output_closed_notify.notify_waiters();
cancellation_token.cancel();
break; break;
} }
} }
} }
drop(close_output);
cancellation_token.cancel();
if final_drain { if final_drain {
tokio::spawn(async move { tokio::spawn(async move {
let _ = process.terminate().await; let _ = process.terminate().await;
}); });
} }
cancellation_token.cancel();
}) })
} }
@@ -677,14 +632,11 @@ impl UnifiedExecProcess {
output_buffer, output_buffer,
output_notify, output_notify,
output_closed, output_closed,
output_closed_notify,
.. ..
} = output_handles; } = output_handles;
let close_output = output_closed.drop_guard();
tokio::spawn(async move { tokio::spawn(async move {
let _output_task_guard = OutputTaskGuard { let _close_output = close_output;
output_closed: Arc::clone(&output_closed),
output_closed_notify: Arc::clone(&output_closed_notify),
};
let mut stdout_open = true; let mut stdout_open = true;
let mut stderr_open = true; let mut stderr_open = true;
while stdout_open || stderr_open { while stdout_open || stderr_open {
@@ -594,10 +594,7 @@ impl UnifiedExecProcessManager {
// Persist live sessions and remote output that remains pollable after an early exit. // Persist live sessions and remote output that remains pollable after an early exit.
let process_stored = (!process.has_exited() && process.exit_code().is_none()) let process_stored = (!process.has_exited() && process.exit_code().is_none())
|| (process.output_handles().drain_policy == OutputDrainPolicy::WaitForOutputClosure || (process.output_handles().drain_policy == OutputDrainPolicy::WaitForOutputClosure
&& !process && !process.output_handles().output_closed.is_cancelled());
.output_handles()
.output_closed
.load(Ordering::Acquire));
let mut initial_exec_command_guard = InitialExecCommandGuard { let mut initial_exec_command_guard = InitialExecCommandGuard {
active: None, active: None,
metrics_sidecar, metrics_sidecar,
@@ -1139,7 +1136,7 @@ impl UnifiedExecProcessManager {
if retention == OutputRetention::UntilCollected if retention == OutputRetention::UntilCollected
&& output.drain_policy == OutputDrainPolicy::WaitForOutputClosure && output.drain_policy == OutputDrainPolicy::WaitForOutputClosure
&& !entry.process.termination_requested.load(Ordering::Acquire) && !entry.process.termination_requested.load(Ordering::Acquire)
&& (!output.output_closed.load(Ordering::Acquire) && (!output.output_closed.is_cancelled()
|| output || output
.output_buffer .output_buffer
.try_lock() .try_lock()
@@ -1537,12 +1534,10 @@ impl UnifiedExecProcessManager {
output_buffer, output_buffer,
output_notify, output_notify,
output_closed, output_closed,
output_closed_notify,
cancellation_token, cancellation_token,
.. ..
} = output; } = output;
let mut collected = HeadTailBuffer::default(); let mut collected = HeadTailBuffer::default();
let mut exit_signal_received = cancellation_token.is_cancelled();
let mut post_exit_deadline: Option<Instant> = None; let mut post_exit_deadline: Option<Instant> = None;
let stop_reason = loop { let stop_reason = loop {
Self::extend_deadlines_while_paused( Self::extend_deadlines_while_paused(
@@ -1551,22 +1546,14 @@ impl UnifiedExecProcessManager {
&mut post_exit_deadline, &mut post_exit_deadline,
) )
.await; .await;
let drained_output: HeadTailBuffer<MAX_BYTES>; // Subscribe before draining. If closure races the drain, wake and
let has_drained_output: bool; // drain again so the last chunk cannot land between an empty read and exit.
let mut wait_for_output = None; let notified = output_notify.notified();
{ let closed = output_closed.is_cancelled();
let mut guard = output_buffer.lock().await; let drained_output = std::mem::take(&mut output_buffer.lock().await.pending);
drained_output = std::mem::take(&mut guard.pending); if drained_output.total_bytes() == 0 {
has_drained_output = let exit_signal_received = cancellation_token.is_cancelled();
drained_output.retained_bytes() > 0 || drained_output.omitted_bytes() > 0; if exit_signal_received && closed {
if !has_drained_output {
wait_for_output = Some(output_notify.notified());
}
}
if !has_drained_output {
exit_signal_received |= cancellation_token.is_cancelled();
if exit_signal_received && output_closed.load(Ordering::Acquire) {
break StopReason::OutputClosed; break StopReason::OutputClosed;
} }
let remaining = deadline.saturating_duration_since(Instant::now()); let remaining = deadline.saturating_duration_since(Instant::now());
@@ -1582,26 +1569,18 @@ impl UnifiedExecProcessManager {
if close_wait_remaining == Duration::ZERO { if close_wait_remaining == Duration::ZERO {
break StopReason::PostExitDeadline; break StopReason::PostExitDeadline;
} }
let notified = wait_for_output.unwrap_or_else(|| output_notify.notified());
let closed = output_closed_notify.notified();
tokio::pin!(notified);
tokio::pin!(closed);
tokio::select! { tokio::select! {
_ = &mut notified => {} _ = notified => {}
_ = &mut closed => {} _ = output_closed.cancelled() => {}
_ = tokio::time::sleep(close_wait_remaining) => break StopReason::PostExitDeadline, _ = tokio::time::sleep(close_wait_remaining) => break StopReason::PostExitDeadline,
_ = Self::wait_for_pause_change(pause_state.as_ref()) => {} _ = Self::wait_for_pause_change(pause_state.as_ref()) => {}
} }
continue; continue;
} }
let notified = wait_for_output.unwrap_or_else(|| output_notify.notified());
tokio::pin!(notified);
let exit_notified = cancellation_token.cancelled();
tokio::pin!(exit_notified);
tokio::select! { tokio::select! {
_ = &mut notified => {} _ = notified => {}
_ = &mut exit_notified => exit_signal_received = true, _ = cancellation_token.cancelled() => {}
_ = tokio::time::sleep(remaining) => break StopReason::Deadline, _ = tokio::time::sleep(remaining) => break StopReason::Deadline,
_ = Self::wait_for_pause_change(pause_state.as_ref()) => {} _ = Self::wait_for_pause_change(pause_state.as_ref()) => {}
} }
@@ -1610,7 +1589,6 @@ impl UnifiedExecProcessManager {
collected.push_buffer(drained_output); collected.push_buffer(drained_output);
exit_signal_received |= cancellation_token.is_cancelled();
if Instant::now() >= deadline { if Instant::now() >= deadline {
break StopReason::Deadline; break StopReason::Deadline;
} }
@@ -1625,11 +1603,8 @@ impl UnifiedExecProcessManager {
StopReason::PostExitDeadline => "post_exit_deadline", StopReason::PostExitDeadline => "post_exit_deadline",
}, },
); );
span.record( span.record("exit_signaled", cancellation_token.is_cancelled());
"exit_signaled", span.record("output_closed", output_closed.is_cancelled());
exit_signal_received || cancellation_token.is_cancelled(),
);
span.record("output_closed", output_closed.load(Ordering::Acquire));
span.record("outcome", "completed"); span.record("outcome", "completed");
collected collected
} }
@@ -377,61 +377,49 @@ fn initial_exec_yield_time_has_no_platform_floor() {
); );
} }
#[tokio::test] #[tokio::test(start_paused = true)]
async fn output_collection_stays_bounded_across_repeated_drains() { async fn output_collection_stays_bounded_across_repeated_drains() {
let chunks: [&[u8]; 4] = [b"01234567", b"89ABCDEF", b"ghijklmnopq", b"rs"];
let output_buffer = Arc::new(tokio::sync::Mutex::new(OutputBuffers::<10>::default()));
let output_notify = Arc::new(Notify::new());
let output_closed = Arc::new(AtomicBool::new(false));
let output_closed_notify = Arc::new(Notify::new());
let cancellation_token = CancellationToken::new();
let output = OutputHandles { let output = OutputHandles {
output_buffer: Arc::clone(&output_buffer), output_buffer: Arc::new(tokio::sync::Mutex::new(OutputBuffers::<10>::default())),
output_notify: Arc::clone(&output_notify), output_notify: Arc::new(Notify::new()),
output_closed: Arc::clone(&output_closed), output_closed: CancellationToken::new(),
output_closed_notify: Arc::clone(&output_closed_notify), cancellation_token: CancellationToken::new(),
cancellation_token: cancellation_token.clone(),
collection_finished: CancellationToken::new(), collection_finished: CancellationToken::new(),
drain_policy: OutputDrainPolicy::BoundedAfterExit, drain_policy: OutputDrainPolicy::BoundedAfterExit,
}; };
let collect = UnifiedExecProcessManager::collect_output_until_deadline( let collect = UnifiedExecProcessManager::collect_output_until_deadline(
&output, &output,
/*pause_state*/ None, /*pause_state*/ None,
Instant::now() + Duration::from_secs(5), Instant::now() + Duration::from_secs(5),
); );
let produce = async { tokio::pin!(collect);
let chunks: [&[u8]; 3] = [b"01234567", b"89ABCDEF", b"ghijklmnopq"];
for chunk in chunks { for chunk in chunks {
output_buffer output
.output_buffer
.lock() .lock()
.await .await
.push_chunk(ExecOutputStream::Stdout, chunk); .push_chunk(ExecOutputStream::Stdout, chunk);
output_notify.notify_one(); output.output_notify.notify_waiters();
tokio::time::timeout(Duration::from_secs(1), async { assert!(futures::poll!(collect.as_mut()).is_pending());
loop { assert_eq!(output.output_buffer.lock().await.pending.total_bytes(), 0);
if output_buffer.lock().await.pending.retained_bytes() == 0 {
break;
} }
tokio::task::yield_now().await;
} // Closure alone must wake the post-exit wait and drain the last bytes.
}) output.cancellation_token.cancel();
assert!(futures::poll!(collect.as_mut()).is_pending());
output
.output_buffer
.lock()
.await .await
.expect("collector should drain each chunk"); .push_chunk(ExecOutputStream::Stdout, b"rs");
} output.output_closed.cancel();
output_closed.store(true, Ordering::Release);
cancellation_token.cancel();
output_closed_notify.notify_waiters();
output_notify.notify_waiters();
};
let (collected, ()) = tokio::join!(collect, produce);
let mut expected = HeadTailBuffer::<10>::default(); let mut expected = HeadTailBuffer::<10>::default();
for chunk in chunks { expected.push_chunk(b"0123456789ABCDEFghijklmnopqrs");
expected.push_chunk(chunk); assert_eq!(collect.await, expected);
} assert_eq!(output.output_buffer.lock().await.transcript, expected);
assert_eq!(collected, expected);
assert_eq!(output_buffer.lock().await.transcript, expected);
} }
#[tokio::test] #[tokio::test]
@@ -444,20 +432,17 @@ async fn output_collection_preserves_omissions_from_drained_buffer() {
expected.push_chunk(b"overflow"); expected.push_chunk(b"overflow");
let output_buffer = Arc::new(tokio::sync::Mutex::new(buffered_output)); let output_buffer = Arc::new(tokio::sync::Mutex::new(buffered_output));
let output_notify = Arc::new(Notify::new()); let output_notify = Arc::new(Notify::new());
let output_closed = Arc::new(AtomicBool::new(true));
let output_closed_notify = Arc::new(Notify::new());
let cancellation_token = CancellationToken::new();
cancellation_token.cancel();
let output = OutputHandles { let output = OutputHandles {
output_buffer, output_buffer,
output_notify, output_notify,
output_closed, output_closed: CancellationToken::new(),
output_closed_notify, cancellation_token: CancellationToken::new(),
cancellation_token,
collection_finished: CancellationToken::new(), collection_finished: CancellationToken::new(),
drain_policy: OutputDrainPolicy::BoundedAfterExit, drain_policy: OutputDrainPolicy::BoundedAfterExit,
}; };
output.output_closed.cancel();
output.cancellation_token.cancel();
let collected = UnifiedExecProcessManager::collect_output_until_deadline( let collected = UnifiedExecProcessManager::collect_output_until_deadline(
&output, &output,
/*pause_state*/ None, /*pause_state*/ None,
@@ -212,15 +212,12 @@ async fn remote_lifecycle_updates_preserve_recovered_exit_state(write_status: Wr
// A rejected write first reports exit without a status. The final read then // A rejected write first reports exit without a status. The final read then
// recovers the executor's actual exit code and sandbox-denial classification. // recovers the executor's actual exit code and sandbox-denial classification.
let closed = process.output_handles().output_closed_notify.notified();
tokio::pin!(closed);
closed.as_mut().enable();
process.output_handles().collection_finished.cancel(); process.output_handles().collection_finished.cancel();
assert!(matches!( assert!(matches!(
process.write(b"hello").await, process.write(b"hello").await,
Err(UnifiedExecError::WriteToStdin) Err(UnifiedExecError::WriteToStdin)
)); ));
closed.await; process.output_handles().output_closed.cancelled().await;
assert!(matches!( assert!(matches!(
process.write(b"hello").await, process.write(b"hello").await,
@@ -314,11 +311,8 @@ async fn closed_output_is_classified_without_waiting_for_more_output() {
.lock() .lock()
.await .await
.push_chunk(ExecOutputStream::Stderr, b"permission denied"); .push_chunk(ExecOutputStream::Stderr, b"permission denied");
let closed = output.output_closed_notify.notified();
tokio::pin!(closed);
closed.as_mut().enable();
process.terminate_confirmed().await.expect("terminate"); process.terminate_confirmed().await.expect("terminate");
closed.await; output.output_closed.cancelled().await;
let start = tokio::time::Instant::now(); let start = tokio::time::Instant::now();
let result = process.check_for_sandbox_denial().await; let result = process.check_for_sandbox_denial().await;