{"record":{"id":"ffe12bd45611b533","repo":"nautechsystems/nautilus_trader","slug":"failed-to-open-file-after-max-retries-attem","errorCode":null,"errorMessage":"Failed to open file '{}' after {max_retries} attempts: {e}","messagePattern":"Failed to open file '(.+?)' after (.+?) attempts: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/tardis/src/csv/mod.rs","lineNumber":88,"sourceCode":"fn create_csv_reader<P: AsRef<Path>>(\n    filepath: P,\n) -> anyhow::Result<Reader<Box<dyn std::io::Read>>> {\n    const MAX_RETRIES: u8 = 3;\n    const DELAY_MS: u64 = 100;\n    const BUFFER_SIZE: usize = 8 * 1024 * 1024; // 8MB buffer for large files\n\n    fn open_file_with_retry<P: AsRef<Path>>(\n        path: P,\n        max_retries: u8,\n        delay_ms: u64,\n    ) -> anyhow::Result<File> {\n        let path_ref = path.as_ref();\n        for attempt in 1..=max_retries {\n            match File::open(path_ref) {\n                Ok(file) => return Ok(file),\n                Err(e) => {\n                    if attempt == max_retries {\n                        anyhow::bail!(\n                            \"Failed to open file '{}' after {max_retries} attempts: {e}\",\n                            path_ref.display()\n                        );\n                    }\n                    log::warn!(\n                        \"Attempt {attempt}/{max_retries} failed to open file '{}': {e}. Retrying after {delay_ms}ms...\",\n                        path_ref.display()\n                    );\n                    std::thread::sleep(Duration::from_millis(delay_ms));\n                }\n            }\n        }\n        unreachable!(\"Loop should return either Ok or Err\");\n    }\n\n    let filepath_ref = filepath.as_ref();\n    let mut file = open_file_with_retry(filepath_ref, MAX_RETRIES, DELAY_MS)?;\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/tardis/src/csv/mod.rs#L70-L106","documentation":"open_file_with_retry opens a file with up to max_retries attempts, sleeping between attempts. If every attempt fails (e.g. file missing, locked, or permission denied), it bails with this message including the path, attempt count, and the last underlying IO error.","triggerScenarios":"Calling create_csv_reader on a path that cannot be opened after all retry attempts — nonexistent path, permission denied, file locked by another process, or transient network-filesystem failure.","commonSituations":"Wrong path in dataset configuration; file not yet fully downloaded/uploaded; Windows file locking by another reader; NFS/S3-mounted files with transient unavailability.","solutions":["Verify the file path exists and is readable (check spelling, working directory, permissions)","Check the underlying error {e} in the message: NotFound means fix the path; PermissionDenied means fix file ACLs","Wait for the file to finish downloading/being written before processing","Increase max_retries/delay if the storage is transiently unavailable"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"use std::path::Path;\nfn can_open(path: impl AsRef<Path>) -> bool {\n    path.as_ref().is_file() && std::fs::metadata(&path)\n        .map(|m| m.len() > 0).unwrap_or(false)\n        // plus a probe: File::open(path).is_ok()\n}","typeGuard":null,"tryCatchPattern":"match create_csv_reader(path) {\n    Ok(reader) => /* proceed */,\n    Err(e) if e.to_string().contains(\"Failed to open file\") => {\n        log::error!(\"file unavailable: {e:#}\");\n        // fix path/permissions or wait and retry\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Verify paths and permissions before loading datasets","Ensure files are fully downloaded/written before reading","Avoid sharing open files across processes on platforms with locking","Increase retry count/delay for network-attached storage"],"tags":["tardis","csv","file-io","retry"],"backgroundTag":"file-open-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}