Skip to content

Commit 02da4a0

Browse files
revonateB0TDude so hot
andauthored
fix(io): avoid livelock between flush and shutdown (#912)
* Try fix deadlock * Avoid allocation --------- Co-authored-by: Dude so hot <djohn@fbi.gov>
1 parent 51d7ac5 commit 02da4a0

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

compio-io/src/compat/async_stream.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ pin_project! {
141141
write_waker: Option<Waker>,
142142
flush_waker: Option<Waker>,
143143
close_waker: Option<Waker>,
144+
closed: bool,
144145
#[pin]
145146
_p: PhantomPinned,
146147
}
@@ -169,6 +170,7 @@ impl<S> AsyncWriteStream<S> {
169170
write_waker: None,
170171
flush_waker: None,
171172
close_waker: None,
173+
closed: false,
172174
_p: PhantomPinned,
173175
}
174176
}
@@ -402,6 +404,9 @@ impl<S: AsyncWrite + Unpin + 'static> AsyncWriteStream<S> {
402404
}
403405

404406
fn poll_close_impl(self: Pin<&mut Self>) -> Poll<io::Result<()>> {
407+
if self.closed {
408+
return Poll::Ready(Ok(()));
409+
}
405410
let this = self.project();
406411
// SAFETY:
407412
// - The future won't live longer than the stream.
@@ -415,7 +420,7 @@ impl<S: AsyncWrite + Unpin + 'static> AsyncWriteStream<S> {
415420
arr.with(|waker| {
416421
let cx = &mut Context::from_waker(waker);
417422
let res = poll_future!(this.shutdown_future, cx, inner.get_mut().shutdown());
418-
Poll::Ready(res)
423+
Poll::Ready(res.inspect(|_| *this.closed = true))
419424
})
420425
}
421426
}

0 commit comments

Comments
 (0)