{"record":{"id":"7349a04264d08832","repo":"pola-rs/polars","slug":"finish-open-could-not-acquire-shared-lock-on-data-file-at","errorCode":null,"errorMessage":"finish_open: could not acquire shared lock on data file at {:?}","messagePattern":"finish_open: could not acquire shared lock on data file at (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-io/src/file_cache/entry.rs","lineNumber":393,"sourceCode":"        {\n            std::fs::OpenOptions::new()\n                .read(true)\n                .open(data_file_path)\n                .unwrap()\n        }\n        // windows requires write access to update the last accessed time\n        #[cfg(target_family = \"windows\")]\n        {\n            std::fs::OpenOptions::new()\n                .read(true)\n                .write(true)\n                .open(data_file_path)\n                .unwrap()\n        }\n    };\n    update_last_accessed(&file);\n    if FileExt::try_lock_shared(&file).is_err() {\n        panic!(\n            \"finish_open: could not acquire shared lock on data file at {:?}\",\n            data_file_path\n        );\n    }\n    file\n}\n\n/// `[prefix]/d/[uri hash][last modified]`\nfn get_data_file_path(\n    path_prefix: &[u8],\n    uri_hash: &[u8],\n    remote_version: &FileVersion,\n) -> PathBuf {\n    let owned;\n    let path = [\n        path_prefix,\n        &[b'/', DATA_PREFIX, b'/'],\n        uri_hash,","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-io/src/file_cache/entry.rs#L375-L411","documentation":"finish_open must acquire a shared advisory file lock (flock) on the cached data file to read it safely; if try_lock_shared fails it panics. This guards against concurrent eviction/modification while reading. Failure indicates lock contention with an evicting writer or an OS/filesystem that doesn't support the lock.","triggerScenarios":"Opening a cached cloud file (try_open_assume_latest / try_open_check_latest) while another process/thread holds an exclusive lock (eviction in progress), or on filesystems without flock support (some network mounts).","commonSituations":"NFS/SMB mounts lacking flock, concurrent Polars processes racing eviction, or lock-holder processes killed leaving inconsistent state on exotic filesystems.","solutions":["Retry the read; transient contention with the eviction task usually resolves quickly","Avoid sharing the cache directory across filesystems that don't support flock (use a local disk via POLARS_TEMP_DIR)","Ensure no other process holds an exclusive lock on the cached file","Disable/limit concurrent eviction or use separate cache dirs per job"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-check: ensure cache lives on a local filesystem that supports flock\nlet base = std::env::var(\"POLARS_TEMP_DIR\").unwrap_or_else(|_| std::env::temp_dir().display().to_string());\nassert!(!base.starts_with(\"/mnt/nfs\"), \"file cache on NFS may not support flock; use a local disk\");","typeGuard":null,"tryCatchPattern":"// The API panics rather than returning Err; catch at process level or retry the job\nfor attempt in 0..3 {\n    let result = std::panic::catch_unwind(|| read_cached(path));\n    if result.is_ok() { break; }\n    std::thread::sleep(std::time::Duration::from_millis(200 * (attempt + 1)));\n}","preventionTips":["Keep the file cache on local disk, not NFS/SMB","Avoid many concurrent processes sharing one cache directory with aggressive eviction","Retry transient lock contention at the job level"],"tags":["filesystem","cache","lock","concurrency","panic"],"backgroundTag":"invalid-state-transition","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}