Fix panic when sending error to closed channel#1338
Open
zhengxiexie wants to merge 1 commit intovmware-tanzu:mainfrom
Open
Fix panic when sending error to closed channel#1338zhengxiexie wants to merge 1 commit intovmware-tanzu:mainfrom
zhengxiexie wants to merge 1 commit intovmware-tanzu:mainfrom
Conversation
Add safeSendError helper function to handle the case where fatalErrors channel may be closed when PopulateResourcetoStore tries to send errors. This prevents potential panics during store initialization. Change-Id: Ia5cdcba37b8080b65141584ab5393b2d2913a1c6
39124aa to
8924a31
Compare
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (55.55%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #1338 +/- ##
==========================================
- Coverage 76.36% 76.36% -0.01%
==========================================
Files 149 149
Lines 20679 20687 +8
==========================================
+ Hits 15791 15797 +6
- Misses 3757 3758 +1
- Partials 1131 1132 +1
🚀 New features to boost your workflow:
|
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's Changed
Safe Channel Error Handling
safeSendErrorhelper function to prevent panics when sending errors to a potentially closed channelPopulateResourcetoStoreto use safe error sending with fallback loggingImplementation Details
safeSendErrorfunction inpkg/nsx/services/common/store.go🎯 Motivation
SR Background: Production environment reported panic during store initialization:
Issue: When
PopulateResourcetoStoreencounters an error, it sends to thefatalErrorschannel. If the channel receiver has already closed the channel (e.g., due to timeout or another goroutine's fatal error), this causes a panic that crashes the operator.Solution: Wrap channel send in a safe helper that recovers from panics and logs the error as a fallback, ensuring the operator remains stable even when concurrent error handling races occur.
✅ Testing
🔄 Backward Compatibility
This change is fully backward compatible - it only adds safety handling without changing existing behavior when the channel is open.