Repository navigation
refactor: decompose God Files xclient.go (1444→231) and server.go (1098→299) - #939
Merged
Merged
Conversation
Move service-discovery, server-filtering, and cached-client-management methods out of xclient.go (God File, Critical #1) into a focused xclient_discovery.go. Same package, pure mechanical move — no logic, API, or behavior change. Moved: watch, filterByStateAndGroup, selectClient, safeCloseClient, getCachedClient/setCachedClient/findCachedClient/deleteCachedClient/ removeClient/generateClient/getCachedClientWithoutLock, splitNetworkAndAddress.
Move core invocation (Go, Call, Oneshot, SendRaw) and their helpers (setServerTimeout, uncoverError, contextCanceled, wrapCall, wrapSendRaw) out of xclient.go into xclient_call.go. Same package, mechanical move.
Move Broadcast, Fork, Inform out of xclient.go into xclient_broadcast.go. Same package, mechanical move.
…sfer.go Move SendFile, DownloadFile, Stream out of xclient.go into xclient_transfer.go. Close stays in xclient.go (lifecycle). Same package, mechanical move. xclient.go is now 231 lines (down from 1444); the God File (Critical #1) is decomposed into 5 cohesive files: xclient.go (home/types/ctors), xclient_discovery.go, xclient_call.go, xclient_broadcast.go, xclient_transfer.go.
Move handleRequest, handleRequestForFunction, handleError out of server.go into server_dispatch.go. Same package, mechanical move.
Move sendResponse and SendMessage out of server.go into server_response.go. Same package, mechanical move.
Move serveListener, serveConn, processOneRequest, parseServerTimeout, isShutdown, closeConn, readRequest, auth out of server.go into server_conn.go. Same package, mechanical move.
Move getDoneChan, Close, RegisterOnShutdown, RegisterOnRestart, Shutdown, Restart, startProcess, checkProcessMsg, closeDoneChanLocked (and shutdownPollInterval) out of server.go into server_shutdown.go. Same package, mechanical move. server.go is now 299 lines (down from 1098); the God File (Critical #2) is decomposed into 5 cohesive files: server.go (home/types/ctors/Serve), server_conn.go, server_dispatch.go, server_response.go, server_shutdown.go.
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
Decomposes the two God Files flagged as Critical in the smell report (
tasks/smell-report-2026-06-30-2329.md, follow-up to PR #938):client/xclient.go— 1444 → 231 linesserver/server.go— 1098 → 299 linesEach is split into 5 cohesive files within the same package. No logic, API, or behavior change — pure mechanical move of declarations between files in the same package.
Why same-package file decomposition (not true sub-packages)
A deep-dive found both
xClientandServerare shared-mutable-receiver God Objects: nearly every method acquires the samemumutex and touches the same field set (servers,cachedClient,auth,Plugins,isShutdown,selector). Hub methods (selectClient,getCachedClient,sendResponse,handleRequest) are called across what would be separate concerns. Go forbids defining one struct's methods across packages, so true sub-package extraction would require breaking the shared struct into multiple types plus internal interfaces/accessors — a rewrite touching the hot path and forcing internal-access tests to move. That's major-version work, deferred. This file decomposition is the safe prerequisite: each concern now sits in its own focused, scannable file, and a future major-version split has clear boundaries to extract.Files
client/ (package client unchanged)
xclient.goxclient_discovery.goxclient_call.goxclient_broadcast.goxclient_transfer.goserver/ (package server unchanged; existing separate files like gateway.go/plugin.go/service.go untouched)
server.goserver_conn.goserver_dispatch.goserver_response.goserver_shutdown.goDiff: 10 files, +2120 / -2012 (net +108 = 8 file-header comments + reformatted imports).
How it was done
For each file: extracted contiguous decl blocks to the new file via sed, let
goimportsresolve exact imports, deleted the blocks from the source,gofmt, then build + vet + test. One file per commit (8 commits) so each is independently revertible. Code text is unchanged — only which file a declaration lives in.Test status
go build ./...— cleango vet ./client/... ./server/...— clean (one pre-existing warning inplugin_test.go:56, untouched, unrelated)go test ./share/... ./protocol/... ./codec/... ./client/... ./server/...— all passgo test -race -run 'TestShutdownHook|TestPluginHeartbeat' ./server/— pass (the de-flaked tests from PR refactor: smell-report fixes — panics, dead sort, swallowed errors, test de-flake #938 still green)gofmt-cleanBackward compatibility
Package import paths unchanged (
github.com/smallnest/rpcx/client,.../server). All exported types/methods remain in place. External consumers (serverplugin,clientplugin) use only public interfaces — verified unaffected. Same-package move means the shared receiver, mutex, fields, and internal-access tests all work exactly as before.Checklist
Not in this PR (deferred to a major version)
client/discover,server/gateway, etc.) — requires breaking the shared mutable receiver into multiple types + internal interfaces; a rewrite suited to a major version. This file decomposition is the safe prerequisite that makes it tractable.