refactor(traefik): improve config removal logic and error handling#4115
Merged
Siumauricio merged 1 commit intocanaryfrom Mar 30, 2026
Conversation
- Consolidated command execution for removing Traefik config files by using a single command string. - Enhanced error handling to log issues encountered during the removal process for both local and remote configurations.
Comment on lines
64
to
66
| } else { | ||
| if (fs.existsSync(configPath)) { | ||
| await fs.promises.unlink(configPath); | ||
| } | ||
| } | ||
| if (fs.existsSync(configPath)) { | ||
| await fs.promises.unlink(configPath); | ||
| await execAsync(command); | ||
| } |
Contributor
There was a problem hiding this comment.
Prefer native
fs API over shell for local file removal
The previous code used fs.promises.unlink (with an existence check) for the local path, which avoids spawning a shell process entirely. Replacing it with execAsync("rm -f ...") introduces two minor concerns:
- Unnecessary shell overhead: spinning up a child process to call
rmis heavier than a direct syscall viafs.promises.unlink. - Path injection surface: if
appNameever contained shell metacharacters (spaces, semicolons, backticks, etc.) the unquotedconfigPathin the command string would be interpreted by the shell. Wrapping the path in quotes, or reverting to the native API, removes this class of risk.
Suggested change
| } else { | |
| if (fs.existsSync(configPath)) { | |
| await fs.promises.unlink(configPath); | |
| } | |
| } | |
| if (fs.existsSync(configPath)) { | |
| await fs.promises.unlink(configPath); | |
| await execAsync(command); | |
| } | |
| } else { | |
| try { | |
| await fs.promises.unlink(configPath); | |
| } catch (err: any) { | |
| if (err?.code !== "ENOENT") throw err; | |
| } | |
| } |
This mirrors the -f / "ignore missing file" semantics while keeping the local path on the safer, shell-free code path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this PR about?
Please describe in a short paragraph what this PR is about.
Checklist
Before submitting this PR, please make sure that:
canarybranch.Issues related (if applicable)
closes #4086
Screenshots (if applicable)
Greptile Summary
This PR refactors the Traefik config removal helpers in
application.tswith three improvements: it fixes a genuine bug where localfs.promises.unlinkwas called unconditionally even after a successful remoterm(the final block sat outside theif/else); it adds the-fflag tormso missing-file errors are silently ignored on both local and remote paths; and it adds structuredconsole.errorlogging to the previously emptycatchblocks.Key observations
serverIdwas set (i.e., a remote server target).-fflag addition is a good defensive improvement, eliminating spurious errors when a config file is already absent.execAsync("rm -f ...")instead of the previousfs.promises.unlinkcall. This is consistent with the remote approach but introduces an avoidable shell spawn and leaves the unquotedconfigPathvariable susceptible to shell metacharacter interpretation ifappNameever contains special characters. Usingfs.promises.unlinkwith anENOENTguard would be slightly safer and cheaper for the local case.Confidence Score: 5/5
Safe to merge — fixes a real but low-impact bug and the only remaining finding is a P2 style suggestion.
The PR resolves a confirmed bug (double local deletion on remote path) and improves observability. The single open comment is a P2 style preference (native
fsAPI vs shell) with no current production impact since application names in Dokploy are alphanumeric/hyphen-only and the local path constant is fixed.No files require special attention.
Important Files Changed
unlinkafter remoterm), adds-fto suppress missing-file errors, and improves error logging. Local deletion now usesexecAsyncshell command instead of the nativefsAPI, introducing minor shell-overhead and a theoretical path-injection surface.Reviews (1): Last reviewed commit: "refactor(traefik): improve config remova..." | Re-trigger Greptile