Skip to content

Octopus Server command delete-instance doesn't actually remove the server node from the database #10135

Description

@hnrkndrssn

Severity

Not blocking customers directly, but it means every delete-instance run leaves a permanently orphaned OctopusServerNode row behind. Over time (or after repeated instance recreation using the same node name) this can lead to confusing downstream cluster/locking symptoms, since the database still thinks a long-gone node exists.

Version

Confirmed present since at least 2019

Latest Version

I could reproduce the problem in the latest build

What happened?

Running Octopus.Server delete-instance logs "De-registered <NodeName> from the database.", but the node's row in the OctopusServerNode table is never actually deleted.

The cleanup code builds its DELETE using the raw node name:

var commandText = $"DELETE FROM [OctopusServerNode] WHERE [Id] = @serverName";
connection.ExecuteNonQuery(commandText, new Dictionary<string, object> { { "serverName", serverName } });

but OctopusServerNode.Id is always "OctopusServerNodes-" + name, not the raw name. The WHERE clause never matches anything, so the DELETE silently affects 0 rows. Because the row count isn't checked, the "De-registered..." log message is written regardless of whether anything was actually removed.

Interestingly, the equivalent cleanup for OctopusServerNodeStatus a couple of lines below gets this right — it does wrap the value in the proper ID-building helper. Only the OctopusServerNode delete has the mismatch.

Reproduction

  1. Set up an Octopus Server instance and note its server node name (defaults to the machine name).
  2. Run Octopus.Server.exe delete-instance --instance <InstanceName> against it.
  3. Observe the log line De-registered <NodeName> from the database.
  4. Query the database directly: SELECT * FROM [OctopusServerNode] WHERE [Id] = 'OctopusServerNodes-<NodeName>' — the row is still present.

Error and Stacktrace

N/A — this fails silently. No exception is thrown; the DELETE simply matches and affects 0 rows.

More Information

No response

Workaround

After confirming the Octopus Server process has fully stopped (otherwise its heartbeat will just re-insert the row), manually remove the stale row:

DELETE FROM [OctopusServerNode] WHERE [Id] = 'OctopusServerNodes-<NodeName>'

Metadata

Metadata

Assignees

Labels

kind/bugThis issue represents a verified problem we are committed to solving

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions