Fix unsafe type assertions and add panic recovery in background handlers#430
Open
WHOIM1205 wants to merge 1 commit intolitmuschaos:stagingfrom
Open
Fix unsafe type assertions and add panic recovery in background handlers#430WHOIM1205 wants to merge 1 commit intolitmuschaos:stagingfrom
WHOIM1205 wants to merge 1 commit intolitmuschaos:stagingfrom
Conversation
Signed-off-by: WHOIM1205 <rathourprateek8@gmail.com>
Author
|
Hi @amityt This PR adds defensive handling for GitHub API responses in the background analytics handler to prevent panics from unsafe type assertions and to ensure the updater continues running across transient API errors (rate limits, outages, unexpected payloads). I’d really appreciate a review when you have time — especially on the error-handling approach and goroutine recovery logic. Thanks |
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.
Summary
This PR fixes a critical crash in the ChartHub community analytics background handler caused by unsafe type assertions on GitHub API responses.
The handler was assuming that all GitHub API responses always contain
typeandnamefields with string values. In real production scenarios (rate limiting, API errors, malformed responses), this assumption breaks and causes a panic inside a background goroutine. Since the goroutine had no recovery mechanism, it would terminate permanently, causing community analytics data to stop updating silently.This change makes the handler resilient to unexpected GitHub API responses and ensures analytics updates continue even after transient failures.
Problem
The background analytics handler performs direct type assertions on GitHub API responses:
dirD["type"].(string)dirD["name"].(string)If the GitHub API returns:
nullvalues,the type assertion panics.
Because the handler runs in an unsupervised background goroutine:
/communityAPI continues serving stale data with no visible error.This failure mode is completely silent and production-impacting.
Root Cause
Fix
This PR introduces three minimal, targeted fixes:
Safe type assertions
typeandnamefieldsPanic recovery in the background handler
recover()to prevent permanent goroutine deathHTTP response validation
These changes preserve existing behavior while preventing crashes and silent failures.
How to Reproduce (Before Fix)
Scenario 1: GitHub API Rate Limit
403with an error JSON payloaddirD["type"].(string)Scenario 2: GitHub API Error
api.github.comor simulate a 5xx responseImpact After Fix
This significantly improves reliability for production and LFX/CNCF-scale deployments where API rate limits and transient failures are common.
Scope of Change
Checklist