Skip to content

Commit

Permalink
Fix possible timer deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Ludwig committed May 4, 2022
1 parent 2b3e3fc commit 0f2a4fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 4 additions & 2 deletions handler/transport/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,10 @@ func (b *Backend) withTimeout(req *http.Request, conf *Config) <-chan error {
ttfbTimer.Reset(conf.TTFBTimeout)
select {
case <-c.Done():
if !ttfbTimer.Stop() {
<-ttfbTimer.C
ttfbTimer.Stop()
select {
case <-ttfbTimer.C:
default:
}
case t := <-ttfbTimer.C:
// buffered, no select done required
Expand Down
5 changes: 2 additions & 3 deletions server/http_endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestBackend_BackendVariable_RequestResponse(t *testing.T) {
responseLogs, _ := entry.Data["response"].(logging.Fields)
data, _ := entry.Data["custom"].(logrus.Fields)

if data != nil && entry.Data["url"] == "http://localhost:8081/token" {
if data != nil && entry.Data["backend"] == "anonymous_76_16" {
expected := logrus.Fields{
"x-from-request-body": "grant_type=client_credentials",
"x-from-request-form-body": "client_credentials",
Expand Down Expand Up @@ -699,7 +699,7 @@ func TestEndpointSequenceClientCancel(t *testing.T) {
helper.Must(err)
}

time.Sleep(time.Second / 2)
time.Sleep(time.Second * 2)

logs := hook.AllEntries()

Expand Down Expand Up @@ -733,7 +733,6 @@ func TestEndpointSequenceClientCancel(t *testing.T) {
if !ctxCanceledSeen || !statusOKseen {
t.Errorf("Expected one sucessful and one failed backend request")
}

}

func TestEndpointSequenceBackendTimeout(t *testing.T) {
Expand Down

0 comments on commit 0f2a4fb

Please sign in to comment.