fix: prevent infinite Readdirnames loops in audit manager and enforce non-nil errors in ConcurrentErrorSlice#4587
Open
pillatipriyanka wants to merge 5 commits into
Conversation
|
|
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR makes several small robustness/cleanup updates across upgrade, audit, readiness logging, and a concurrency utility.
Changes:
- Updates upgrade
Managerconstruction and comment to reflect upgrade usage. - Makes
ConcurrentErrorSlice.Last()safe on empty slices. - Improves audit directory cleanup / JSON unmarshal patterns and simplifies readiness logging.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/upgrade/manager.go | Adjusts New() and manager initialization for upgrade usage. |
| pkg/syncutil/concurrent_slice.go | Avoids panic by returning nil when no errors exist. |
| pkg/readiness/list.go | Simplifies error logging message/fields during listing retries. |
| pkg/audit/manager.go | Tweaks directory deletion loop error handling and simplifies unstructured JSON unmarshal. |
ce16ca7 to
6083b9f
Compare
Comment on lines
+788
to
+799
| if len(names) > 0 { | ||
| files = append(files, names...) | ||
| } | ||
| if err == nil { | ||
| continue | ||
| } | ||
| if errors.Is(err, io.EOF) { | ||
| break | ||
| } | ||
| return files, err | ||
| } | ||
| return files, nil |
5452655 to
7772f8f
Compare
Comment on lines
+789
to
+802
| if len(names) == 0 { | ||
| if err == nil || errors.Is(err, io.EOF) { | ||
| break | ||
| } | ||
| return files, err | ||
| } | ||
| files = append(files, names...) | ||
| if err == nil { | ||
| continue | ||
| } | ||
| if errors.Is(err, io.EOF) { | ||
| break | ||
| } | ||
| return files, err |
pillatipriyanka
commented
May 23, 2026
pillatipriyanka
left a comment
Author
There was a problem hiding this comment.
all comments addressed
9bf38fc to
f9abe8d
Compare
Signed-off-by: pillati lakshmi priyanka <pillatilakshmi@gmail.com>
Signed-off-by: pillati lakshmi priyanka <pillatilakshmi@gmail.com>
dd92581 to
03e7cd4
Compare
Signed-off-by: pillati lakshmi priyanka <pillatilakshmi@gmail.com>
Signed-off-by: pillati lakshmi priyanka <pillatilakshmi@gmail.com>
03e7cd4 to
4cce7ec
Compare
…; make ConcurrentErrorSlice zero-value safe Signed-off-by: pillati lakshmi priyanka <pillatilakshmi@gmail.com>
Comment on lines
+39
to
42
| return &Manager{ | ||
| client: mgr.GetClient(), | ||
| mgr: mgr, | ||
| } |
| type ConcurrentErrorSlice struct { | ||
| s []error | ||
| mu *sync.RWMutex | ||
| mu sync.RWMutex |
Comment on lines
12
to
+18
| func NewConcurrentErrorSlice() ConcurrentErrorSlice { | ||
| return ConcurrentErrorSlice{ | ||
| s: make([]error, 0), | ||
| mu: &sync.RWMutex{}, | ||
| s: make([]error, 0), | ||
| } | ||
| } | ||
|
|
||
| func (c ConcurrentErrorSlice) Append(e error) ConcurrentErrorSlice { | ||
| func (c *ConcurrentErrorSlice) Append(e error) { |
| func (am *Manager) readUnstructured(jsonBytes []byte) (*unstructured.Unstructured, error) { | ||
| u := &unstructured.Unstructured{ | ||
| Object: make(map[string]interface{}), | ||
| func (am *Manager) readDirNames(dir *os.File, batchSize int) (names []string, done bool, err error) { |
Contributor
|
@pillatipriyanka can you fix CI and address copilot feedback? |
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 includes targeted refactoring improvements to enhance code quality, error handling, and maintainability across key packages.
Changes
Added bounds checking to Last() method to prevent index out of range panics
Returns nil for empty slices instead of panicking
Improves reliability of concurrent error collection
readUnstructured(): Removed unnecessary empty map initialization
Direct JSON unmarshaling initializes the Object field automatically
Reduces memory allocations and improves performance
removeAllFromDir(): Enhanced error handling
Properly distinguishes between io.EOF and other errors
Prevents incorrectly ignoring read errors
Improved variable shadowing with inline error checks
3. Readiness Package (pkg/readiness/list.go)
Reduced redundant logging in retryLister()
Removed duplicate 'err' parameter from log.Error call
Cleaner and more accurate error logging
4. Upgrade Manager (pkg/upgrade/manager.go)
Improved initialization in New() constructor
Initialize client field at construction instead of leaving it nil
Prevents nil pointer dereference risks
Cleaner and more efficient code
Fixed documentation: Corrected comment from "audit" to "upgrade"
Impact
✅ Prevents runtime panics in concurrent error handling
✅ Reduces memory allocations in JSON unmarshaling
✅ Improves error handling robustness
✅ Enhances code maintainability and clarity
✅ No breaking changes or functional modifications
Testing
All changes maintain existing functionality while improving implementation details. Code compiles successfully without errors.
Type
Refactoring
Code Quality Improvement
Bug Prevention