io: allow clear_readiness after io driver shutdown (#6067)

This commit is contained in:
Alice Ryhl 2023-10-12 17:18:22 +02:00 committed by GitHub
parent d420d528f9
commit 0f296d2089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -210,8 +210,8 @@ impl ScheduledIo {
pub(super) fn set_readiness(&self, tick: Tick, f: impl Fn(Ready) -> Ready) {
let mut current = self.readiness.load(Acquire);
// The shutdown bit should not be set
debug_assert_eq!(0, SHUTDOWN.unpack(current));
// If the io driver is shut down, then you are only allowed to clear readiness.
debug_assert!(SHUTDOWN.unpack(current) == 0 || matches!(tick, Tick::Clear(_)));
loop {
// Mask out the tick bits so that the modifying function doesn't see

View File

@ -578,6 +578,23 @@ fn driver_shutdown_wakes_poll() {
assert_err!(futures::executor::block_on(poll_writable(&afd_a)));
}
#[test]
fn driver_shutdown_then_clear_readiness() {
let rt = rt();
let (a, _b) = socketpair();
let afd_a = {
let _enter = rt.enter();
AsyncFd::new(a).unwrap()
};
let mut write_ready = rt.block_on(afd_a.writable()).unwrap();
std::mem::drop(rt);
write_ready.clear_ready();
}
#[test]
fn driver_shutdown_wakes_poll_race() {
// TODO: make this a loom test