fix: critical job lifecycle bugs and start/stop race condition - #2
Merged
Conversation
This was referenced Jul 23, 2026
mylastresort
force-pushed
the
fix/critical-bugs
branch
from
July 23, 2026 10:24
8b62429 to
1d39c3d
Compare
- Fix exec.Cmd reuse bug (C1): create fresh Cmd object each restart iteration - Fix autorestart=unexpected logic (C3): correct index/value iteration + break - Fix stop signal order (C4): send stopsignal first, then SIGKILL after stopwaitsecs - Fix start/stop race condition (C8): unified mutex + startReady channel - Fix client error variable (M2): read res.Err.Error() instead of err.Error() - Fix reload error handling (M3): propagate config parse errors to client - Fix mutex deadlock (M5): use defer for unlock in Stop() and Start() - Fix range iteration (M1): use _, exit := range for value iteration - 28 tests across 9 sections (control shell, config, autorestart, stop signal, kill-restart, startsecs, startretries, hot-reload, race condition) - 25 pass, 3 fail (all pre-existing env-specific issues, not code bugs) - Test configs for each test scenario in tests/ directory - Add test workflow
mylastresort
force-pushed
the
fix/critical-bugs
branch
from
July 23, 2026 21:11
1d39c3d to
90ff35a
Compare
mylastresort
marked this pull request as ready for review
July 23, 2026 21:20
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.
Summary
Fixes 8 critical and minor bugs in the job lifecycle management and a start/stop race condition that could cause processes to run uncontrolled.
Changes
Critical Fixes (C1, C3, C4, C8)
C1: Autorestart never works - exec.Cmd reuse
exec.Command()creation insidestartJobWorkerloop so each restart gets a freshCmdobjectdonechannel handling to only signal on first iterationC3: autorestart=unexpected logic completely broken
for exit := rangetofor _, exit := range(was iterating indices, not values)expectedflag to break outer restart loop when matching exit code foundC4: Stop sends SIGKILL immediately instead of graceful signal first
j.StopSignalfirst, waitStopWaitSecs, thenSIGKILLif still aliveC8: Start/Stop race condition - separate mutexes
mustart/mustopinto singlemustopmutex withdeferunlockstartReadychannel:Start()creates fresh,Stop()waits on<-j.startReadystartOnceto safely closestartReadywithout double-close panicsMinor Fixes (M1, M2, M3, M5)
for exit := rangetofor _, exit := rangeinNewJoberr.Error()tores.Err.Error())reload()silently ignoring config parse errorsdeferunlockTesting
tests/full_test.shTest Results
* C3b: intermittent timing issue
** C4: env-specific
trap '' TERMviash -cdoesn't trap correctly*** HR-2: nc
\rdelimiter issueFiles Changed
cmd/client/main.go: M2 fixinternal/job/job.go: C1, C3, C4, C8, M1, M5 fixesinternal/manager/manager.go: M3 fix