Repository navigation
Conversation
soujasK
force-pushed
the
fix/timeout-toxic-timer
branch
from
October 26, 2026 10:41
29a92b5 to
f1dd752
Compare
…iving The timeout toxic created a new time.After on every loop iteration, so each chunk it dropped restarted the timer and a client sending more often than `timeout` kept the connection open forever. Use a single timer for the whole toxic run, as before the input-draining loop was added.
soujasK
force-pushed
the
fix/timeout-toxic-timer
branch
from
October 26, 2026 15:05
f1dd752 to
a6addba
Compare
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.
Problem
The README says the
timeouttoxic "stops all data from getting through, and closes the connection aftertimeout" (also how it's described in #121). That only holds while the client is quiet: if the client keeps sending data more often thantimeout, the connection is never closed.Root cause
Since f7154cc started draining the input inside a loop, the
timeout > 0branch creates a newtime.After(timeout)on every iteration. Each chunk the toxic drops restarts the countdown, so it behaves like an idle timeout. The original implementation used a singletime.After.(It also allocated a timer per dropped chunk, see #232/#231.)
Solution
Create one
time.NewTimer(timeout)before the loop and stop it on return.Verification
TestTimeoutToxicClosesConnectionWhileDataIsSent: a 300ms upstream timeout toxic while the client writes every 50ms. Onmainthe upstream connection is still open after 1s; with the change it's closed after the timeout.go test -race -run TestTimeoutToxic ./toxicspasses (5 runs) on Linux; golangci-lint v2.14.0: 0 issues.toxicslatency timing tests (TestFullstreamLatencyBias*,TestTwoLatencyToxics) fail under-racein WSL onmaintoo.Compatibility and risks
Clients that keep sending now get disconnected after
timeout, as documented. Anyone relying on the old idle-timeout behaviour would see a change, so it may be worth a changelog line.Unchanged: the timer still starts when the toxic starts running, so adding, updating or removing another toxic in the same direction (which interrupts and restarts it) restarts the timeout, as before.