Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 5, 2026

  • Fix resource leak in newRaftGroup function when raft.NewRaft fails
  • Fix resource leak in newRaftGroup function when r.BootstrapCluster fails
  • Ensure proper cleanup of BoltDB stores (ldb, sdb) and file snapshot store (fss)
  • Test the changes to ensure no regressions
  • Run linter and address any issues
  • Add cache directories to .gitignore
  • Refactor cleanup logic to use helper function
  • Remove accidentally committed cache files (11,038 files)
  • Add clarifying comments about cleanup function placement and error handling

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits February 5, 2026 13:57
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 AI changed the title [WIP] WIP address feedback on coordinator logic refactor Fix resource leaks in multiraft_runtime.go error paths Feb 5, 2026
Copilot AI requested a review from bootjp February 5, 2026 14:03
@bootjp
Copy link
Owner

bootjp commented Feb 5, 2026

@copilot do not commit cache files

Co-authored-by: bootjp <1306365+bootjp@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 5, 2026

@copilot do not commit cache files

Fixed in c8c2d9f. Removed all 11,038 accidentally committed cache files (.cache/ and .golangci-cache/). The .gitignore already includes these directories to prevent future commits.

@bootjp bootjp requested a review from Copilot February 5, 2026 14:18
@bootjp bootjp marked this pull request as ready for review February 5, 2026 14:22
Copy link

Copilot AI left a 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.

Comment on lines 45 to 48
ldb, err := boltdb.NewBoltStore(filepath.Join(dir, "logs.dat"))
if err != nil {
return nil, nil, errors.WithStack(err)
}
Copy link

Copilot AI Feb 5, 2026

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.

Copilot uses AI. Check for mistakes.
Copy link
Owner

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

Copy link
Contributor Author

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>
@bootjp bootjp merged commit 21b8b9a into feature/multi-raft Feb 5, 2026
4 checks passed
@bootjp bootjp deleted the copilot/sub-pr-304-again branch February 5, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants