{"record":{"id":"b17a8fefda711e11","repo":"influxdata/influxdb","slug":"failed-to-rename-temp-directory-to-target","errorCode":null,"errorMessage":"Failed to rename temp directory to target","messagePattern":"Failed to rename temp directory to target","errorType":"exception","errorClass":"ProcessingEngineError","httpStatus":null,"severity":"error","filePath":"influxdb3_processing_engine/src/lib.rs","lineNumber":1260,"sourceCode":"                    tokio::spawn(async move {\n                        let _ = async_fs::remove_dir_all(temp_clone).await;\n                    });\n                    ProcessingEngineError::PluginError(PluginError::AnyhowError(e))\n                })?;\n        }\n\n        let rename_result = async_fs::rename(&temp_path, &plugin_path).await;\n\n        if let Err(e) = rename_result {\n            // Rollback: restore old directory if it exists\n            if old_path.exists() {\n                let _ = async_fs::rename(&old_path, &plugin_path).await;\n            }\n            let _ = async_fs::remove_dir_all(&temp_path).await;\n\n            return Err(ProcessingEngineError::PluginError(\n                PluginError::AnyhowError(\n                    anyhow!(e).context(\"Failed to rename temp directory to target\"),\n                ),\n            ));\n        }\n\n        if old_path.exists() {\n            async_fs::remove_dir_all(&old_path)\n                .await\n                .context(\"Failed to delete old directory\")\n                .map_err(|e| ProcessingEngineError::PluginError(PluginError::AnyhowError(e)))?;\n        }\n\n        Ok(db_name)\n    }\n}\n\n#[derive(Debug)]\npub struct PluginFileInfo {\n    pub plugin_name: Arc<str>,","sourceCodeStart":1242,"sourceCodeEnd":1278,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_processing_engine/src/lib.rs#L1242-L1278","documentation":"Thrown in replace_plugin_directory when the async_fs::rename of the staged temp directory to the final plugin directory target fails (the `e` is wrapped with this context). The rename step is the atomic swap of the new plugin set; its failure means the replacement could not complete. The code attempts to roll back by renaming the old dir back and removing the temp dir.","triggerScenarios":"replace_plugin_directory called when the target plugin path already exists as a non-empty directory (rename fails across platforms), the temp and target are on different filesystems/mounts, or the parent directory is not writable.","commonSituations":"Plugin directory on a Docker volume while temp dir is in container-local storage (EXDEV cross-device link); stale target directory left by a previous failed replace; permission issues after container user changes; Windows target path locked by another process.","solutions":["Ensure the temp directory and the plugin target are on the same filesystem/mount (e.g. both under the same volume).","Remove any leftover target plugin directory from a previously failed replace, then retry.","Check write permissions on the plugin directory's parent for the server process user.","Retry the replace operation; the code already attempts rollback (restores old dir, removes temp)."],"exampleFix":"// before: temp dir outside the plugins volume\ntemp in /tmp, target in /var/lib/influxdb3/plugins\n// after: same filesystem\nlet temp_path = plugin_dir.join(\".tmp-replace\");","handlingStrategy":"retry","validationCode":"// same-filesystem check before replace\nconst sameFs = fs.statSync(tempDir).dev === fs.statSync(path.dirname(targetDir)).dev;\nif (!sameFs) throw new Error('temp dir must be on the same filesystem as plugin dir');","typeGuard":null,"tryCatchPattern":"try {\n  await replacePluginDirectory(files);\n} catch (e) {\n  if (String(e).includes('Failed to rename temp directory')) {\n    fs.rmSync(targetDir, { recursive: true, force: true }); // clear stale target\n    await replacePluginDirectory(files); // retry once\n  } else { throw e; }\n}","preventionTips":["Stage temp dirs inside the same volume as the plugin directory.","Clean up leftover `.tmp`/stale target dirs after failed replaces.","Ensure the server process user owns the plugin dir's parent.","Retry replaces; the operation attempts rollback on failure."],"tags":["filesystem","plugin-directory","atomic-rename"],"backgroundTag":"file-write-failed","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}