Skip to content

fix: close the connection after the timeout even while data keeps arriving - #786

Closed
soujasK wants to merge 1 commit into
Shopify:mainfrom
soujasK:fix/timeout-toxic-timer
Closed

soujasK wants to merge 1 commit into
Shopify:mainfrom
soujasK:fix/timeout-toxic-timer

Conversation

@soujasK

@soujasK soujasK commented Oct 25, 2026

Copy link
Copy Markdown

Problem

The README says the timeout toxic "stops all data from getting through, and closes the connection after timeout" (also how it's described in #121). That only holds while the client is quiet: if the client keeps sending data more often than timeout, the connection is never closed.

Root cause

Since f7154cc started draining the input inside a loop, the timeout > 0 branch creates a new time.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 single time.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

  • New TestTimeoutToxicClosesConnectionWhileDataIsSent: a 300ms upstream timeout toxic while the client writes every 50ms. On main the upstream connection is still open after 1s; with the change it's closed after the timeout.
  • go test -race -run TestTimeoutToxic ./toxics passes (5 runs) on Linux; golangci-lint v2.14.0: 0 issues.
  • On my machine some toxics latency timing tests (TestFullstreamLatencyBias*, TestTwoLatencyToxics) fail under -race in WSL on main too.

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.

…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
soujasK force-pushed the fix/timeout-toxic-timer branch from f1dd752 to a6addba Compare October 26, 2026 15:05
@soujasK soujasK closed this Oct 31, 2026
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.

1 participant