Repository navigation
Description
Description
LogService client creation ignores the caller's cancellation while discovering shard replicas. connectToLogServiceByReverseProxy calls GetShardInfo, which starts the discovery RPC with context.Background() and its own fixed 1-second timeout. A canceled or expired logservice.NewClient call therefore waits for discovery to finish if that endpoint accepts a connection but stops responding.
Environment
- MatrixOne
upstream/mainLogService and TN WAL client code as ofae9e665f30(the scoped files are unchanged from the audit branch base). - Reproduced with a local TCP listener that accepts the discovery connection and sends no response. No full TN process or three-replica cluster was started for this reproducer.
Reproduction
Run TestNewClientDiscoveryIgnoresContextDeadline in pkg/logservice/shardinfo_test.go from the audit branch. It creates a NewClient request with a 20 ms deadline and DiscoveryAddress pointing to the silent listener.
go test ./pkg/logservice -run '^TestNewClientDiscoveryIgnoresContextDeadline$' -count=3 -vOrdinary runs returned after 1.0009, 1.0006 and 1.0012 seconds; two -race runs returned after 1.0016 and 1.0005 seconds. All returned context deadline exceeded, but roughly 980 ms after the caller's deadline. This is bounded by the discovery RPC's own 1-second timeout; this reproduction does not show a multi-minute delay.
Expected Result
Discovery should inherit the NewClient caller context. Once the caller cancels or its deadline expires, client creation should finish promptly rather than waiting for an independent discovery timeout.
Actual Path and Impact
pkg/logservice/client.go:NewClientpasses its context tonewClient, butconnectToLogServiceByReverseProxycalls the context-freeGetShardInfo.pkg/logservice/shardinfo.go:GetShardInfopassescontext.Background()intoqueryShardInfoRawFn;queryShardInfoRawadds a 1-second timeout.pkg/tnservice/factory.go: TN constructs WAL LogService clients withDiscoveryAddressand a context-aware factory.logservicedriver/clientpool.gouses that factory forGetOnFlyContext, including checkpoint Truncate.
A silent discovery endpoint can therefore add up to about 1 second to a canceled TN WAL client-creation attempt. The test proves this for the real LogService client and TCP transport, but does not measure full TN shutdown or transaction latency.
Suggested Regression
After making discovery context-aware, keep a silent TCP discovery endpoint and assert that a 20 ms NewClient deadline returns promptly. Also verify that the existing public GetShardInfo callers retain their intended timeout behavior.
Activity