Repository navigation
fix(runner): keep the TCP rules file watcher alive - #233
Merged
Merged
Conversation
New started a watcher on the -rules file and then closed it with a defer as soon as it returned, so rule changes were never reloaded while the server ran. The watch goroutine also treated the closed Events channel as "continue", which spun a CPU core forever. Keep the watcher on the Runner and close it in Close, and make the watch goroutine return once its channels are closed. Signed-off-by: hakarrr <191973953+hakarrr@users.noreply.github.com> Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Mzack9999
approved these changes
Dec 2, 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.
In
-tcpmoderunner.Newstarts a file watcher on the-rulesfile for live reload, then runsdefer watcher.Close()and returns. The watcher is closed before the server even starts, so editing the rules file never changes the running server. Worse, the goroutine inwatchFiledoesif !ok { continue }on the closedEventschannel, which spins one CPU core at 100% for the whole run.Changes: the watcher is stored on
Runnerand closed inClose(); the goroutine returns whenEventsorErrorsis closed.Tests: new
TestTCPRulesAreReloadedWhenFileChangesstarts the TCP server with a rule answering pong1, rewrites the rules file to answer pong2, and expects pong2. It fails on the old code (the server keeps answering pong1).go test -race -count=2 ./internal/runner/passes.