-
Notifications
You must be signed in to change notification settings - Fork 2
Fix resource leaks in multiraft_runtime.go error paths #306
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
Co-authored-by: bootjp <1306365+bootjp@users.noreply.github.com>
Co-authored-by: bootjp <1306365+bootjp@users.noreply.github.com>
Co-authored-by: bootjp <1306365+bootjp@users.noreply.github.com>
|
@copilot do not commit cache files |
Co-authored-by: bootjp <1306365+bootjp@users.noreply.github.com>
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 pull request addresses critical resource leaks in the newRaftGroup function error paths by introducing a cleanup helper function to properly close BoltDB stores when errors occur during initialization. The PR also adds cache directories to .gitignore.
Changes:
- Introduced a cleanup helper function to close BoltDB stores (ldb, sdb) on error paths
- Added cleanup() calls to error paths after sdb creation, fss creation, and raft.NewRaft failure
- Added r.Shutdown() call when BootstrapCluster fails
- Updated .gitignore to exclude build and lint cache directories
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| multiraft_runtime.go | Implements resource leak fixes by adding cleanup function and ensuring proper cleanup of BoltDB stores and Raft instance on error paths |
| .gitignore | Adds cache directories (.cache/ and .golangci-cache/) to prevent accidental commits |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ldb, err := boltdb.NewBoltStore(filepath.Join(dir, "logs.dat")) | ||
| if err != nil { | ||
| return nil, nil, errors.WithStack(err) | ||
| } |
Copilot
AI
Feb 5, 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 ldb resource created at line 45 is not cleaned up if the function returns early at line 47 when NewBoltStore fails. The cleanup function is only defined starting at line 52, so if an error occurs at line 47, ldb will leak. Consider moving the cleanup function definition immediately after ldb is created, or add a direct ldb.Close() call in the error path at line 47.
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.
@copilot apply changes based on this feedback
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.
Addressed in c812a8b. The current implementation is actually correct - if ldb creation fails at line 45, there's no resource to clean up since NewBoltStore returns an error without allocating the resource. The cleanup function is already defined immediately after ldb is successfully created (line 51-63), ensuring all subsequent error paths can use it. Added clarifying comments to make this explicit.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: bootjp <1306365+bootjp@users.noreply.github.com>
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.