Skip to content

fix(heartbeat): resolve bug where service could never start#64

Merged
lxowalle merged 1 commit intosipeed:mainfrom
DevEverything01:fix/heartbeat-service-start-bug
Feb 12, 2026
Merged

fix(heartbeat): resolve bug where service could never start#64
lxowalle merged 1 commit intosipeed:mainfrom
DevEverything01:fix/heartbeat-service-start-bug

Conversation

@DevEverything01
Copy link
Contributor

@DevEverything01 DevEverything01 commented Feb 12, 2026

Summary

  • HeartbeatService.Start() never launched the goroutine due to a logic error in state detection: running() checks whether stopChan is closed, but a newly created service has an open channel, so running() always returned true, causing Start() to exit early thinking it was already running.
  • Introduced a started bool field to separate "has been started" from "has not been stopped", which also prevents a potential double-close panic when Stop() is called more than once.
State started stopChan Behavior
New false open Start() proceeds, launches goroutine
Running true open Start() is idempotent (no-op)
Stopped false closed Stop() is idempotent, runLoop exits

Test plan

  • go build ./... passes
  • go vet ./pkg/heartbeat/... passes
  • Verify heartbeat goroutine launches after Start() (enable heartbeat in config, observe periodic heartbeat logs)
  • Verify Stop() is safe to call multiple times without panic

HeartbeatService.Start() always returned early because running()
checked stopChan closure state, which is "open" (= true) for a
newly created service. This caused Start() to interpret a fresh
service as "already running" and skip launching the goroutine.

Introduce a `started` bool field to separate "has been started"
from "has not been stopped", fixing both the start failure and
a potential double-close panic on Stop().
@lxowalle
Copy link
Collaborator

Thanks for the pr!

@lxowalle lxowalle merged commit a8cd784 into sipeed:main Feb 12, 2026
emadomedher pushed a commit to emadomedher/picoclaw that referenced this pull request Feb 17, 2026
…ce-start-bug

fix(heartbeat): resolve bug where service could never start
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.

2 participants