Skip to content

[Bug]: LogService client discovery ignores NewClient cancellation for up to 1 second #32916

Open

Description

@jiangxinmeng1

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/main LogService and TN WAL client code as of ae9e665f30 (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 -v

Ordinary 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: NewClient passes its context to newClient, but connectToLogServiceByReverseProxy calls the context-free GetShardInfo.
  • pkg/logservice/shardinfo.go: GetShardInfo passes context.Background() into queryShardInfoRawFn; queryShardInfoRaw adds a 1-second timeout.
  • pkg/tnservice/factory.go: TN constructs WAL LogService clients with DiscoveryAddress and a context-aware factory. logservicedriver/clientpool.go uses that factory for GetOnFlyContext, 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions