Merge pull request #189 from darhwa/http-outbound

Fix the coarse-grained mutex in http outbound
pull/2740/head
Kslr 2020-09-13 14:28:26 +08:00 committed by GitHub
commit 3d855206c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -210,9 +210,10 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
} }
cachedH2Mutex.Lock() cachedH2Mutex.Lock()
defer cachedH2Mutex.Unlock() cachedConn, cachedConnFound := cachedH2Conns[dest]
cachedH2Mutex.Unlock()
if cachedConn, found := cachedH2Conns[dest]; found { if cachedConnFound {
rc, cc := cachedConn.rawConn, cachedConn.h2Conn rc, cc := cachedConn.rawConn, cachedConn.h2Conn
if cc.CanTakeNewRequest() { if cc.CanTakeNewRequest() {
proxyConn, err := connectHTTP2(rc, cc) proxyConn, err := connectHTTP2(rc, cc)
@ -260,6 +261,7 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
return nil, err return nil, err
} }
cachedH2Mutex.Lock()
if cachedH2Conns == nil { if cachedH2Conns == nil {
cachedH2Conns = make(map[net.Destination]h2Conn) cachedH2Conns = make(map[net.Destination]h2Conn)
} }
@ -268,6 +270,7 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
rawConn: rawConn, rawConn: rawConn,
h2Conn: h2clientConn, h2Conn: h2clientConn,
} }
cachedH2Mutex.Unlock()
return proxyConn, err return proxyConn, err
default: default: