Restart HeartbeatProcess on transient pipe errors#391
Merged
Conversation
When the monitor subprocess exits unexpectedly (e.g. due to a transient network/Redis error), @pipe.write raises IOError or Errno::EPIPE. With abort_on_exception=true on the heartbeat thread, this killed the entire worker mid-run, causing tests to be skipped. HeartbeatProcess#tick! now catches these errors, restarts the subprocess via a new restart! method, and retries up to MAX_RESTART_ATTEMPTS (3) consecutive failures before re-raising. The counter resets on each successful tick so transient errors don't exhaust the budget permanently. Also adds mocha as a dev dependency and a dedicated test file covering retry, restart, max-attempts, and counter-reset behaviour.
thadcraft-shopify
approved these changes
Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, if the
HeartbeatProcessmonitor subprocess exited unexpectedly -- due to a transient Redis connection error, OOM killer, or OS signal -- the next@pipe.writeinsend_messagewould raiseIOError: closed streamorErrno::EPIPE. Since the heartbeat thread runs withabort_on_exception = true, this killed the worker mid-run, causing tests to be skipped and connections not returned to the pool.HeartbeatProcess#tick!now rescues those errors, restarts the subprocess via a newrestart!method, and retries. It allows up toMAX_RESTART_ATTEMPTS(3) consecutive failures before re-raising, and resets the counter on each successful tick so transient errors don't exhaust the budget permanently.Also adds mocha as a dev dependency for the new unit tests.