Skip to content

Save new worker registration with its first heartbeat - #91

Merged
raphael merged 1 commit into
mainfrom
worker-registration-heartbeat
Oct 6, 2026
Merged

raphael merged 1 commit into
mainfrom
worker-registration-heartbeat

Conversation

@raphael

@raphael raphael commented Oct 6, 2026

Copy link
Copy Markdown
Member

A pool node can try to clean up a worker while another node is still creating it. The constructor previously saved the worker before its first heartbeat, so cleanup could claim the newly visible worker and make AddWorker fail. Worker registration now saves both records in one Redis operation. Repeating that operation returns the same first heartbeat, so a delayed command cannot replace the timestamp the constructor is waiting for.

The pool owns registration and cleanup. It checks that the pool, node, and original worker stream are still active before saving anything. A failed constructor destroys its stream before removing both registration records; if destruction fails or another node has claimed cleanup, it preserves the records that cleanup needs. AddWorker also checks lifecycle state without holding the local lock needed for retirement. Callers keep the same inputs and result types, including the existing lifecycle errors.

Stored record formats and public APIs are unchanged. Old and new pool nodes can share the same records, although an older node retains the original constructor race. Review pool/worker_registration.go, Node.AddWorker, and newWorker first.

@raphael
raphael merged commit 4182b80 into main Oct 6, 2026
6 checks passed
@raphael
raphael deleted the worker-registration-heartbeat branch October 6, 2026 17:37
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.

1 participant