fix(toxics/bandwidth): don't hang or panic when rate <= 0 - #764
Open
jaideeppyne wants to merge 1 commit into
Open
fix(toxics/bandwidth): don't hang or panic when rate <= 0#764jaideeppyne wants to merge 1 commit into
jaideeppyne wants to merge 1 commit into
Conversation
BandwidthToxic.Pipe already treats a non-positive rate as "no throttling" (sleep = 0), but the packet-splitting loop used t.Rate*100 as the split size unconditionally. With rate == 0 that size is 0, so the loop spins forever emitting empty chunks (p.Data[:0]) and never forwards the payload; with rate < 0 the size is negative and p.Data[:negative] panics with "slice bounds out of range". Guard the loop on t.Rate > 0 so a non-positive rate falls through to the normal (unthrottled) send path. Adds a regression test covering rate 0 (no hang) and rate -1 (no panic).
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
BandwidthToxic.Pipealready treats a non-positiverateas "no throttling" (if t.Rate <= 0 { sleep = 0 }), but the packet-splitting loop usedt.Rate*100as the split size unconditionally:rate == 0→ split size is0, solen(p.Data) > 0stays true forever; the loop spins emitting empty chunks (p.Data[:0]) and never forwards the payload — the connection hangs.rate < 0→ split size is negative;p.Data[:negative]panics withslice bounds out of range.A bandwidth toxic created with
rate: 0(the zero value when the field is omitted) is enough to trigger the hang; there is no input validation rejectingrate <= 0.Fix
Guard the split loop on
t.Rate > 0so a non-positive rate falls through to the normal unthrottled send path — matching the existingt.Rate <= 0intent.Tests
Added
TestBandwidthToxicNonPositiveRate(rate_0,rate_-1), which fails before the change (empty forward / panic) and passes after. Fulltoxicspackage passes;gofmt/go vetclean.