fix(metrics): fallback to mock writer on file open failure to prevent panic#596
Open
abhaygoudannavar wants to merge 2 commits intourunc-dev:mainfrom
Open
fix(metrics): fallback to mock writer on file open failure to prevent panic#596abhaygoudannavar wants to merge 2 commits intourunc-dev:mainfrom
abhaygoudannavar wants to merge 2 commits intourunc-dev:mainfrom
Conversation
When timestamps are enabled but the target file cannot be opened (e.g. missing directory), NewZerologMetrics returned nil. This caused a nil pointer dereference on subsequent metrics.Capture() calls. This fix gracefully degrades to a no-op mockWriter and logs a warning. Signed-off-by: abhaygoudannavar <abhaysgoudnvr@gmail.com>
Added TestZerologMetricsInvalidFileDoesNotPanic to ensure that if the metrics log file cannot be opened, it gracefully degrades instead of causing a nil pointer dereference. Signed-off-by: abhaygoudannavar <abhaysgoudnvr@gmail.com>
✅ Deploy Preview for urunc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
|
Hello @abhaygoudannavar , please do not overwrite the PR description. Read the contribution guide for more information. |
Author
|
@cmainas i have updated the PR description as asked for now it can be merged. |
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.
Description
When timestamps are enabled in the urunc configuration (
/etc/urunc/config.toml) but the target file path is invalid or the parent directory does not exist,NewZerologMetrics()returnsnil. Because the caller assigns this directly without a nil check, any subsequentmetrics.Capture()calls result in a nil pointer dereference, crashing urunc silently.This PR fixes the issue by returning a
&mockWriter{}(safe no-op fallback) and logging a warning instead of returningnilon file open failure. This ensures urunc gracefully disables metrics rather than panicking.Related issues
How was this tested?
/etc/urunc/config.tomlwithenabled = trueand destination set to a non-existent directory (/var/log/urunc/timestamps.log).sudo nerdctl run --rm --runtime io.containerd.urunc.v2 harbor.nbfc.io/nubificus/urunc/nginx-qemu-unikraft-initrd:latest.uruncstarts normally, logs a warning about the file, and gracefully disables metrics without crashing.make unittestto ensure no existing tests were broken.LLM usage
No usage
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).