{"record":{"id":"6ffff9cf35025b67","repo":"tokio-rs/tokio","slug":"a-tokio-1-x-context-was-found-but-it-is-being-shu","errorCode":null,"errorMessage":"A Tokio 1.x context was found, but it is being shutdown.","messagePattern":"A Tokio 1\\.x context was found, but it is being shutdown\\.","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"tokio/src/runtime/io/registration.rs","lineNumber":255,"sourceCode":"        self.handle.driver().io()\n    }\n}\n\nimpl Drop for Registration {\n    fn drop(&mut self) {\n        // It is possible for a cycle to be created between wakers stored in\n        // `ScheduledIo` instances and `Arc<driver::Inner>`. To break this\n        // cycle, wakers are cleared. This is an imperfect solution as it is\n        // possible to store a `Registration` in a waker. In this case, the\n        // cycle would remain.\n        //\n        // See tokio-rs/tokio#3481 for more details.\n        self.shared.clear_wakers();\n    }\n}\n\nfn gone() -> io::Error {\n    io::Error::new(\n        io::ErrorKind::Other,\n        crate::util::error::RUNTIME_SHUTTING_DOWN_ERROR,\n    )\n}\n","sourceCodeStart":237,"sourceCodeEnd":260,"githubUrl":"https://github.com/tokio-rs/tokio/blob/625954f365727668cb02d04172b34f1149637728/tokio/src/runtime/io/registration.rs#L237-L260","documentation":"Registration::gone() returns this io::Error when an I/O resource operation is attempted against an I/O driver that has been shut down. It indicates the ScheduledIo/Registration backing a socket/file is no longer connected to a live driver, so async I/O cannot proceed.","triggerScenarios":"Using an async TcpStream/UdpStream/UnixStream after its runtime's I/O driver has shut down; registering or reading/writing on a resource whose driver Arc has gone away.","commonSituations":"Holding an I/O handle past runtime drop; moving a TcpStream into a 'static task that outlives the runtime; test harnesses that drop the runtime while connections linger.","solutions":["Keep the runtime alive for the entire lifetime of any owned I/O resource.","Close/drop sockets before dropping the runtime.","Detect shutdown via the returned error and propagate it instead of retrying.","Avoid capturing I/O resources in long-lived 'static spawns tied to a shorter-lived runtime."],"exampleFix":"// before\nlet stream = TcpStream::connect(...).await?;\ndrop(runtime);\nstream.read_buf(&mut buf).await?; // returns gone()\n// after\nlet n = stream.read_buf(&mut buf).await;\nmatch n {\n    Err(e) if e.to_string().contains(\"shutting down\") => return,\n    _ => {},\n}","handlingStrategy":"try-catch","validationCode":"// Ensure resource lifetime <= runtime lifetime by design; no cheap runtime check exists.\n// Optionally: assert the runtime guard is held in your API entry points.","typeGuard":null,"tryCatchPattern":"match resource.read_buf(&mut buf).await {\n    Ok(_) => {},\n    Err(e) if e.to_string().contains(\"shutting down\") => {\n        // driver gone: clean up and exit\n        return;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Drop all I/O resources before dropping the runtime.","Never move sockets into 'static tasks tied to a shorter-lived runtime.","Structure shutdown ordering: close sockets, then drop runtime."],"tags":["runtime","io-driver","shutdown","registration","io-error"],"backgroundTag":null,"analyzedSha":"625954f365727668cb02d04172b34f1149637728","analyzedAt":"2026-08-11T17:46:45.378Z","contentChangedAt":"2026-08-11T17:46:45.378Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}