{"record":{"id":"47726d0ce53f05a5","repo":"tokio-rs/tokio","slug":"other-file-operation-is-pending-call-poll-complet","errorCode":null,"errorMessage":"other file operation is pending, call poll_complete before start_seek","messagePattern":"other file operation is pending, call poll_complete before start_seek","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"tokio/src/fs/file.rs","lineNumber":681,"sourceCode":"                            if let Ok(pos) = result {\n                                inner.pos = pos;\n                            }\n                            continue;\n                        }\n                    }\n                }\n            }\n        }\n    }\n}\n\nimpl AsyncSeek for File {\n    fn start_seek(self: Pin<&mut Self>, mut pos: SeekFrom) -> io::Result<()> {\n        let me = self.get_mut();\n        let inner = me.inner.get_mut();\n\n        match inner.state {\n            State::Busy(_) => Err(io::Error::new(\n                io::ErrorKind::Other,\n                \"other file operation is pending, call poll_complete before start_seek\",\n            )),\n            State::Idle(ref mut buf_cell) => {\n                let mut buf = buf_cell.take().unwrap();\n\n                // Factor in any unread data from the buf\n                if !buf.is_empty() {\n                    let n = buf.discard_read();\n\n                    if let SeekFrom::Current(ref mut offset) = pos {\n                        *offset += n;\n                    }\n                }\n\n                let std = me.std.clone();\n\n                inner.state = State::Busy(spawn_blocking(move || {","sourceCodeStart":663,"sourceCodeEnd":699,"githubUrl":"https://github.com/tokio-rs/tokio/blob/625954f365727668cb02d04172b34f1149637728/tokio/src/fs/file.rs#L663-L699","documentation":"Runtime error from `File::start_seek` (file.rs:681). Tokio's `File` refuses to begin a seek while it is in `State::Busy` — a prior read/write operation has not yet completed. The API requires the previous operation to be drained via `poll_complete` before a new `start_seek`. This is an API-usage violation, not an I/O failure.","triggerScenarios":"Calling `AsyncSeekExt::seek` (which calls `start_seek`) on a `File` while a previous `poll_read`/`poll_write` operation is still pending — e.g. interleaving seeks with an in-flight read/write future on the same `File`, or sharing one `File` across tasks without serialization.","commonSituations":"Mixing `AsyncReadExt`/`AsyncWriteExt` and `AsyncSeekExt` calls on the same `File` without fully awaiting each; manually polling the `File`; sharing a `File` across tasks concurrently (Tokio files are not `Sync`-shareable for concurrent ops).","solutions":["Fully `await` the previous read/write operation before issuing a seek on the same `File`.","Prefer the `AsyncSeekExt`/`AsyncReadExt`/`AsyncWriteExt` combinators which enforce the operation ordering.","Do not share one `File` across concurrent tasks; serialize access through a single owner or a channel.","If polling manually, call `poll_complete` to finish the pending op before `start_seek`."],"exampleFix":"// before: seeking while a read future is still pending\nlet n = file.read(&mut buf).await?; // ensure this completes first\nfile.seek(SeekFrom::Start(0)).await?; // OK only after the read resolved\n\n// after: always await prior ops before seeking (serialize on one owner)\nlet n = file.read(&mut buf).await?;\nfile.seek(SeekFrom::Start(0)).await?;\nfile.write(&data).await?;","handlingStrategy":"validation","validationCode":"// Enforce single-owner access to the File; never start a seek while a\n// read/write future is still pending. Await each op to completion first.\n// (Compile-time discipline; no runtime check exists inside File itself.)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fully `await` each read/write before seeking on the same `File`.","Never share one `File` across concurrent tasks; serialize through a single owner.","Prefer the `AsyncReadExt`/`AsyncWriteExt`/`AsyncSeekExt` combinators over manual polling.","If polling manually, always call `poll_complete` before `start_seek`."],"tags":["rust","tokio","fs","async-seek","api-misuse","runtime"],"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"}