Skip to content

fix(logservice): close store on initialization failure#25774

Open
LeftHandCold wants to merge 2 commits into
matrixorigin:mainfrom
LeftHandCold:agent/fix-logservice-init-cleanup
Open

fix(logservice): close store on initialization failure#25774
LeftHandCold wants to merge 2 commits into
matrixorigin:mainfrom
LeftHandCold:agent/fix-logservice-init-cleanup

Conversation

@LeftHandCold

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #25740

What this PR does / why we need it:

NewService creates a live log store before loading local metadata and restoring persisted replicas. If either initialization step returned an error, the constructor returned without closing the store. The orphaned Dragonboat NodeHost kept its gossip/Raft listeners, TanDB handles, directory lock, and truncation worker alive, so an in-process retry with the same configuration failed with an address conflict.

This change closes the store on both error paths while preserving the original initialization error. The successful startup path, on-disk metadata, and RPC behavior are unchanged.

The regression tests exercise both sides of the failure window:

  • an injected metadata open error before replica restoration;
  • dragonboat.ErrShardAlreadyExist after one persisted replica has already been restored.

Each test retries construction with the same UUID, data directory, and network addresses, proving that the NodeHost, workers, listeners, and storage handles were released.

Validation (with the standard MatrixOne CGo environment):

  • go test -v -count=1 -timeout 120s -run 'TestNewServiceClosesStoreOn(Metadata|ReplicaStart)Failure$' ./pkg/logservice
  • go test -race -count=1 -timeout 180s -run 'TestNewServiceClosesStoreOn(Metadata|ReplicaStart)Failure$' ./pkg/logservice
  • go test -v -count=1 -timeout 300s ./pkg/logservice
  • go build ./pkg/logservice
  • go vet ./pkg/logservice

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

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

Labels

kind/bug Something isn't working kind/test-ci size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Logservice leaks NodeHost and workers when metadata or replica initialization fails

3 participants