-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
in case of an open breaker and route has a teeLopback filter like `br…
…eaker -> teeLoopback()`, we did not consume the body such that the cloned request spawned in a goroutine never finished (#1819) Signed-off-by: Sandor Szücs <[email protected]>
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package proxy | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/zalando/skipper/circuit" | ||
"github.com/zalando/skipper/filters/builtin" | ||
) | ||
|
||
func TestBreakerLeak(t *testing.T) { | ||
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(599) | ||
w.Write([]byte("backend")) | ||
})) | ||
defer backend.Close() | ||
|
||
doc := fmt.Sprintf(`main: Path("/leak") -> consecutiveBreaker(1) -> teeLoopback("tag") -> "%s"; shadow: Path("/leak") && Tee("tag") -> <shunt>;`, backend.URL) | ||
fr := builtin.MakeRegistry() | ||
settings := []circuit.BreakerSettings{{ | ||
Type: circuit.ConsecutiveFailures, | ||
Failures: 1, | ||
}} | ||
params := Params{ | ||
Flags: FlagsNone, | ||
CloseIdleConnsPeriod: -1, | ||
CircuitBreakers: circuit.NewRegistry(settings...), | ||
} | ||
|
||
tp, err := newTestProxyWithFiltersAndParams(fr, doc, params, nil) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
defer tp.close() | ||
|
||
r1, _ := http.NewRequest("POST", "http://www.example.org/leak", bytes.NewBufferString("fpp\n")) | ||
w1 := httptest.NewRecorder() | ||
tp.proxy.ServeHTTP(w1, r1) | ||
if w1.Code != 599 { | ||
t.Fatalf("first request wrong status: %d", w1.Code) | ||
} | ||
|
||
buf := bytes.NewBufferString("fpp\n") | ||
r1, _ = http.NewRequest("POST", "http://www.example.org/leak", buf) | ||
w1 = httptest.NewRecorder() | ||
tp.proxy.ServeHTTP(w1, r1) | ||
if w1.Code != 503 { | ||
t.Fatalf("second request wrong status: %d", w1.Code) | ||
} | ||
_, err = buf.ReadByte() | ||
if err != io.EOF { | ||
t.Errorf("request body was not read: %v", err) | ||
} | ||
} |
This file contains 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