Skip to content

fix(runner): keep the TCP rules file watcher alive - #233

Merged
Mzack9999 merged 2 commits into
projectdiscovery:devfrom
hakarrr:fix-tcp-rules-watcher
Dec 2, 2026
Merged

Mzack9999 merged 2 commits into
projectdiscovery:devfrom
hakarrr:fix-tcp-rules-watcher

Conversation

@hakarrr

@hakarrr hakarrr commented Dec 1, 2026

Copy link
Copy Markdown

In -tcp mode runner.New starts a file watcher on the -rules file for live reload, then runs defer 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 in watchFile does if !ok { continue } on the closed Events channel, which spins one CPU core at 100% for the whole run.

Changes: the watcher is stored on Runner and closed in Close(); the goroutine returns when Events or Errors is closed.

Tests: new TestTCPRulesAreReloadedWhenFileChanges starts 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.

hakarrr and others added 2 commits December 1, 2026 20:02
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
Mzack9999 merged commit 4624642 into projectdiscovery:dev Dec 2, 2026
4 checks passed
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.

2 participants