Skip to content

Fix local remove deleting a version in use by a running server#259

Merged
sdairs merged 1 commit into
mainfrom
issue-257-remove-running-version
Jun 18, 2026
Merged

Fix local remove deleting a version in use by a running server#259
sdairs merged 1 commit into
mainfrom
issue-257-remove-running-version

Conversation

@sdairs

@sdairs sdairs commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Fixes #257.

Problem

chctl local remove <version> deleted the installed binary directory unconditionally. If a local server was running on that version, the binary was pulled out from under it — local remove reported success while local server list still showed the server running, now pointing at a deleted binary.

Fix

local remove <version> now:

  • Recovers orphaned servers, then refuses to delete a version that a running server is using, failing with a new VersionInUse error that lists the running server name(s): "Version X is in use by running server(s): default. Stop them first, or pass --force." (exit code 1, nothing deleted).
  • Accepts --force to stop the running server(s) first (printing Stopped server '<name>'), then proceed with the existing default-version/symlink cleanup and removal.

Reuses the same guard pattern as server remove (recover_current_project_servers, list_running_servers, kill_server). Detection/stop is current-project scoped, consistent with those helpers, which covers the reported in-project bug.

Changes

  • src/error.rs — new VersionInUse { version, servers } variant (+ exit-code test).
  • src/local/cli.rs--force flag on Remove, updated help text, two parse tests.
  • src/local/mod.rs — running-server guard in remove().
  • README.md — documented the guard and --force.

Verification

  • cargo build and cargo clippy clean (no warnings).
  • cargo test -p clickhousectl — all passing, including the new parse and exit-code tests.

🤖 Generated with Claude Code


Note

Low Risk
Localized CLI safety change around version removal; reuses existing server stop/discovery helpers with tests and docs.

Overview
clickhousectl local remove no longer deletes an installed ClickHouse binary if a local server in the current project is still running on that version. It recovers orphaned servers, lists matching running instances, and fails with VersionInUse (exit 1) naming those servers unless you stop them first.

Adds --force on local remove to stop those servers via the existing kill_server path, print Stopped server '<name>', then run the usual default-version / symlink cleanup and directory removal. CLI help, README, a new error variant (+ exit-code test), and Remove parse tests document and cover the behavior.

Reviewed by Cursor Bugbot for commit 8b5ef18. Bugbot is set up for automated code reviews on this repo. Configure here.

`local remove <version>` deleted the binary directory unconditionally,
leaving any server running on that version pointing at a deleted binary
(issue #257). It now recovers orphaned servers, refuses to remove a
version that a running server is using (new VersionInUse error listing
the server names), and accepts --force to stop the running server(s)
first. Reuses the existing server remove guard pattern.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sdairs sdairs requested a review from iskakaushik as a code owner June 16, 2026 09:43

@iskakaushik iskakaushik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sdairs sdairs merged commit cb44665 into main Jun 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: local remove should not remove running server

2 participants