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. |
Author
|
@cmainas are there any changes needed in this PR? |
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
This PR fixes a critical nil pointer dereference crash in the metrics initialization process.
When
[timestamps]are enabled in the/etc/urunc/config.tomlconfiguration but the target file path is invalid (e.g., the parent directory does not exist or has bad permissions),NewZerologMetricspreviously returnednil. Because the caller inmain.goassigned this directly to the globalmetricsvariable without a nil check, the very firstmetrics.Capture()call resulted in a silent crash on startup.Changes included:
NewZerologMetricsnow catches the file open error, logs a warning vialogrus, and returns a safe, no-opmockWriterinstead ofnil.TestZerologMetricsInvalidFileDoesNotPanictometrics_test.goto explicitly test the invalid path scenario and ensureCapture()can be called safely without panicking.Screenshots
Fixes: #595
LLM usage
No LLM usage
Checklist
make lint)make unittest)git commit -s)