-
Notifications
You must be signed in to change notification settings - Fork 64
feat: check headers concurrently #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds concurrent header checking to improve performance by processing files in parallel using goroutines and errgroup. The change updates the Check function to check license headers across files concurrently with a limit based on GOMAXPROCS.
Changes:
- Introduced concurrent file processing using
golang.org/x/sync/errgroup - Set concurrency limit to
runtime.GOMAXPROCS(0) - Modified the file checking loop to spawn goroutines for parallel execution
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| g := new(errgroup.Group) | ||
| g.SetLimit(runtime.GOMAXPROCS(0)) | ||
|
|
||
| for _, file := range fileList { | ||
| if err := CheckFile(file, config, result); err != nil { | ||
| return err | ||
| } | ||
| f := file | ||
| g.Go(func() error { | ||
| return CheckFile(f, config, result) | ||
| }) | ||
| } |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Result struct methods (Succeed, Fail, Ignore) perform unsynchronized slice appends in concurrent goroutines, causing race conditions. The Result type (lines 32-42 in result.go) uses direct slice appends without any synchronization mechanism like sync.Mutex. This will lead to data races and potentially lost results or corrupted data when multiple goroutines write to the same Result instance simultaneously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ZacBlanco Is this an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is. I didn't look closely enough into the Result struct. I pushed a version which adds a mutex to make the Result struct's associated methods thread-safe. Accessing the inner slices directly is still not thread-safe but the code does not do anything with the slices directly while the concurrent checks are happening so I think it should be ok
be68d36 to
f46e7ee
Compare
Closes apache/skywalking#13667