Skip to content

Commit 4a167cb

Browse files
committed
Fix data race condition in the Alt-Svc cache
Signed-off-by: roc <roc@imroc.cc>
1 parent 08861d9 commit 4a167cb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

transport.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,9 @@ func (t *Transport) checkAltSvc(req *http.Request) (resp *http.Response, err err
846846
return
847847
}
848848
addr := netutil.AuthorityKey(req.URL)
849+
t.pendingAltSvcsMu.Lock()
849850
pas, ok := t.pendingAltSvcs[addr]
851+
t.pendingAltSvcsMu.Unlock()
850852
if ok && pas.Transport != nil {
851853
pas.Mu.Lock()
852854
if pas.Transport != nil {
@@ -862,7 +864,9 @@ func (t *Transport) checkAltSvc(req *http.Request) (resp *http.Response, err err
862864
}
863865
} else {
864866
t.altSvcJar.SetAltSvc(addr, pas.Entries[pas.CurrentIndex])
867+
t.pendingAltSvcsMu.Lock()
865868
delete(t.pendingAltSvcs, addr)
869+
t.pendingAltSvcsMu.Unlock()
866870
}
867871
}
868872
pas.Mu.Unlock()

0 commit comments

Comments
 (0)