Skip to content

Commit 0f2a4fb

Browse files
author
Marcel Ludwig
committed
Fix possible timer deadlock
golang/go#27169
1 parent 2b3e3fc commit 0f2a4fb

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

handler/transport/backend.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,10 @@ func (b *Backend) withTimeout(req *http.Request, conf *Config) <-chan error {
378378
ttfbTimer.Reset(conf.TTFBTimeout)
379379
select {
380380
case <-c.Done():
381-
if !ttfbTimer.Stop() {
382-
<-ttfbTimer.C
381+
ttfbTimer.Stop()
382+
select {
383+
case <-ttfbTimer.C:
384+
default:
383385
}
384386
case t := <-ttfbTimer.C:
385387
// buffered, no select done required

server/http_endpoints_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestBackend_BackendVariable_RequestResponse(t *testing.T) {
6161
responseLogs, _ := entry.Data["response"].(logging.Fields)
6262
data, _ := entry.Data["custom"].(logrus.Fields)
6363

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

702-
time.Sleep(time.Second / 2)
702+
time.Sleep(time.Second * 2)
703703

704704
logs := hook.AllEntries()
705705

@@ -733,7 +733,6 @@ func TestEndpointSequenceClientCancel(t *testing.T) {
733733
if !ctxCanceledSeen || !statusOKseen {
734734
t.Errorf("Expected one sucessful and one failed backend request")
735735
}
736-
737736
}
738737

739738
func TestEndpointSequenceBackendTimeout(t *testing.T) {

0 commit comments

Comments
 (0)