From ce5c5034bff49ded9cf2fb1dd1b4d637d95c5f77 Mon Sep 17 00:00:00 2001 From: snider Date: Wed, 31 Dec 2025 04:41:47 +0000 Subject: [PATCH] fix: Allow removing stopped miners from manager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, StopMiner would fail if the miner was already stopped (crashed or killed externally), leaving it stuck in the workers list. Now the miner is always removed from the manager, even if Stop() returns "miner is not running". This allows cleaning up dead workers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- pkg/mining/manager.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/mining/manager.go b/pkg/mining/manager.go index 7cd8f76..4e5dbd9 100644 --- a/pkg/mining/manager.go +++ b/pkg/mining/manager.go @@ -351,7 +351,8 @@ func (m *Manager) updateMinerConfig(minerType string, autostart bool, config *Co return SaveMinersConfig(cfg) } -// StopMiner stops a running miner. +// StopMiner stops a running miner and removes it from the manager. +// If the miner is already stopped, it will still be removed from the manager. func (m *Manager) StopMiner(name string) error { m.mu.Lock() defer m.mu.Unlock() @@ -372,11 +373,18 @@ func (m *Manager) StopMiner(name string) error { return fmt.Errorf("miner not found: %s", name) } - if err := miner.Stop(); err != nil { - return err + // Try to stop the miner, but always remove it from the map + // This handles the case where a miner crashed or was killed externally + stopErr := miner.Stop() + + // Always remove from map - if it's not running, we still want to clean it up + delete(m.miners, name) + + // Only return error if it wasn't just "miner is not running" + if stopErr != nil && stopErr.Error() != "miner is not running" { + return stopErr } - delete(m.miners, name) return nil }