Repository navigation
conn: return a close function from NewConfig and remove Config.Close - #352
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Two guide examples omit cleanup, and the documented error-result assertion is missing from the back-channel test.
2 open findings
What changed in this PR
Moves connection-pool ownership from Config views to a close function returned by NewConfig.
Changes:
- Removes
Config.Closeand updates all callers. - Makes pool shutdown idempotent, concurrent-safe, and server-owned for peers.
- Updates lifecycle tests and documentation.
| File | Description |
|---|---|
config.go |
Exposes the new NewConfig signature. |
config_test.go |
Tests pool closure and error behavior. |
internal/conn/config.go |
Returns the pool close function. |
internal/conn/config_test.go |
Removes obsolete close tests. |
internal/conn/outbound_manager.go |
Logs close errors and returns no error. |
server.go |
Stores and invokes peer-pool cleanup. |
server_test.go |
Migrates test cleanup calls. |
server_internal_test.go |
Migrates internal peer helpers. |
gorumstest/gorumstest.go |
Removes Closer and registers close functions. |
gorumstest/servers.go |
Updates example usage. |
examples/storage/client.go |
Uses the returned close function. |
benchkit/benchmark/target.go |
Returns the new cleanup function. |
benchkit/benchmark/benchmark_test.go |
Migrates benchmark test cleanup. |
doc/user-guide.md |
Documents the ownership model. |
doc/dev-guide.md |
Updates internal lifecycle documentation. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Config.Close closed the whole connection pool from any configuration in it, so cfg.Remove(3).Close() also closed node 3. A Config is a plain node slice and cannot record whether it owns the pool, so no rule on Config.Close can avoid this. NewConfig now returns a func() that closes the pool, and Config has no Close method. Only the creator holds the close function; derived configurations are views that cannot close the pool. The close function returns no error: the only error the close path can produce is gRPC's ErrClientConnClosing for a connection that is already closed, and each connection is closed once. The manager logs a node's close error with its logger instead. Server keeps the close function for its peer configuration and calls it in Stop and GracefulStop. gorumstest.Closer existed only to check the close error, so it is removed; tests pass the close function to t.Cleanup directly.
meling
force-pushed
the
feature/314/config-close-func
branch
from
October 10, 2026 11:54
64f15d5 to
e89e325
Compare
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.


Closes #314
Problem
All configurations derived from one
NewConfigcall share one connection pool.Config.Closeclosed that whole pool from any configuration in it, socfg.Remove(3).Close()also closed node 3. #351 documented this rule and fixed the leak and the data race around it, but the rule still surprises users.A
Configis a plain[]*Node. It cannot record whether it owns the pool, so no rule forConfig.Closecan avoid the surprise. Reference counting onNodedoes not work either; see the decision comment on #314.Change
NewConfigreturns a close function, andConfighas noClosemethod:Extend,Remove,Sort,WithoutErrors, slicing) are views and cannot close the pool.Extendadded. It is idempotent and safe for concurrent use.ErrClientConnClosing, for a connection that is already closed, and Gorums closes each connection once. The manager logs a node's close error if a logger is set.NewConfigreturns a nil configuration and a nil close function.Serverkeeps the close function for itsWithPeersconfiguration and calls it inStopandGracefulStop. A handler can no longer close the server's peer pool throughServerContext.PeerConfig().gorumstest.Closerexisted only to check the close error, so it is removed. Tests pass the close function tot.Cleanupdirectly.addNodeandExtendchecks.This is a breaking API change. No release has been made since v0.11.0.
Testing
TestConfigCloseis rewritten around the close function:ClosesExtendedNodes: nodes thatExtendadded are closed too.Idempotent: concurrent calls all return after the nodes are closed.ExtendAfterClose: new node, existing node, and nil source all fail.NewConfigError: a failingNewConfigreturns nil, nil and leaks nothing (goleak). Removing the cleanup on the error path makes this subtest fail.ConcurrentExtend: unchanged.TestNewConfigandTestNewConfigWithBackChannelalso check that both results are nil on error.go test ./...passes in the root,benchkit, andexamplesmodules.go test -race -count=5 . ./internal/conn/ ./gorumstest/passes.go test -tags=integration ./...passes.make modernizeandmake goplscheckare clean for the changed files.