fix(rebuilder): fix rebuilder for windows and goroutine leaks and process lifecycle bugs - #13
Merged
Merged
Conversation
added 3 commits
March 13, 2026 10:51
Extract setSysProcAttr, terminateProcess, and notifyContext into sysproc_unix.go and sysproc_windows.go to isolate platform-specific syscall usage behind a common interface. This enables clean builds on both platforms without build tag complexity in business logic.
… lifecycle - Thread context.Context through Watch() so watcher goroutine exits on shutdown, preventing goroutine and fsnotify file-descriptor leaks - Use context-aware sends in debounce timer callback to prevent blocking after shutdown; add nil-safe debounce.Stop() to avoid panic - Move channel initialization before watcher start to eliminate data race - Add explicit cancel() calls and post-terminate errCh drain to ensure child processes are fully waited on before restart - Guard against empty command panic in startProcess - Collect and return first non-nil error from Serve() via exitCh - Move pflag.Parse() from goroutine to main() for deterministic parsing - Update test expectations and add error-case subtests for empty command and invalid binary scenarios
The package-level maxServiceNameLen accumulated across multiple Serve() calls and test runs (-count>1), causing inconsistent log formatting. Reset to 0 at the start of readProcfile().
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
context.ContextthroughWatch()setSysProcAttr,terminateProcess,notifyContext) intosysproc_unix.go/sysproc_windows.goServe()maxServiceNameLenglobal accumulation across multipleServe()callspflag.Parse()from goroutine tomain()for deterministic parsingBugs Fixed
Watch()defer cancel()insideforloop accumulates contexts per restarterrChonly received errors, not nilreloadChdata race — channels initialized after watcher startedpflag.Parse()called inside goroutineterminateProcess— process not fully reaped before restartmaxServiceNameLenaccumulates across test runs (-count>1)Testing
-race -count=3Serve()API