Skip to content

Commit

Permalink
Merge pull request #169 from Shopify/timeout-hang-bug
Browse files Browse the repository at this point in the history
timeout toxic drops more than just the first segment
  • Loading branch information
jpittis authored Apr 4, 2017
2 parents 476c3aa + 7cda467 commit 90b2bc1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
12 changes: 7 additions & 5 deletions toxics/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ func (t *TimeoutToxic) Pipe(stub *ToxicStub) {
}
}
} else {
select {
case <-stub.Interrupt:
return
case <-stub.Input:
// Drop the data on the ground.
for {
select {
case <-stub.Interrupt:
return
case <-stub.Input:
// Drop the data on the ground.
}
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions toxics/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ func WithEstablishedProxy(t *testing.T, f func(net.Conn, net.Conn, *toxiproxy.Pr
func TestTimeoutToxicDoesNotCauseHang(t *testing.T) {
WithEstablishedProxy(t, func(conn, _ net.Conn, proxy *toxiproxy.Proxy) {
proxy.Toxics.AddToxicJson(ToxicToJson(t, "might_block", "latency", "upstream", &toxics.LatencyToxic{Latency: 10}))
proxy.Toxics.AddToxicJson(ToxicToJson(t, "to_delete", "timeout", "upstream", &toxics.TimeoutToxic{Timeout: 0}))
proxy.Toxics.AddToxicJson(ToxicToJson(t, "timeout", "timeout", "upstream", &toxics.TimeoutToxic{Timeout: 0}))

_, err := conn.Write([]byte("hello"))
if err != nil {
t.Fatal("Unable to write to proxy", err)
for i := 0; i < 5; i++ {
_, err := conn.Write([]byte("hello"))
if err != nil {
t.Fatal("Unable to write to proxy", err)
}
time.Sleep(200 * time.Millisecond) // Shitty sync waiting for latency toxi to get data.
}

time.Sleep(1 * time.Second) // Shitty sync waiting for latency toxi to get data.

err = testhelper.TimeoutAfter(time.Second, func() {
err := testhelper.TimeoutAfter(time.Second, func() {
proxy.Toxics.RemoveToxic("might_block")
})
if err != nil {
Expand Down

0 comments on commit 90b2bc1

Please sign in to comment.