mirror of
https://github.com/MetaCubeX/Clash.Meta.git
synced 2025-04-07 07:03:33 +03:00
fix: shut it down more aggressively in grpc transport closing
This commit is contained in:
parent
b0bd4f4caf
commit
efa224373f
1 changed files with 24 additions and 1 deletions
|
@ -1,7 +1,10 @@
|
|||
package gun
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/http2"
|
||||
|
@ -13,11 +16,31 @@ type clientConnPool struct {
|
|||
conns map[string][]*http2.ClientConn // key is host:port
|
||||
}
|
||||
|
||||
type clientConn struct {
|
||||
t *http.Transport
|
||||
tconn net.Conn // usually *tls.Conn, except specialized impls
|
||||
}
|
||||
|
||||
type efaceWords struct {
|
||||
typ unsafe.Pointer
|
||||
data unsafe.Pointer
|
||||
}
|
||||
|
||||
type tlsConn interface {
|
||||
net.Conn
|
||||
NetConn() net.Conn
|
||||
}
|
||||
|
||||
func closeClientConn(cc *http2.ClientConn) { // like forceCloseConn() in http2.ClientConn but also apply for tls-like conn
|
||||
if conn, ok := (*clientConn)(unsafe.Pointer(cc)).tconn.(tlsConn); ok {
|
||||
t := time.AfterFunc(time.Second, func() {
|
||||
_ = conn.NetConn().Close()
|
||||
})
|
||||
defer t.Stop()
|
||||
}
|
||||
_ = cc.Close()
|
||||
}
|
||||
|
||||
func (tw *TransportWrap) Close() error {
|
||||
connPool := transportConnPool(tw.Transport)
|
||||
p := (*clientConnPool)((*efaceWords)(unsafe.Pointer(&connPool)).data)
|
||||
|
@ -25,7 +48,7 @@ func (tw *TransportWrap) Close() error {
|
|||
defer p.mu.Unlock()
|
||||
for _, vv := range p.conns {
|
||||
for _, cc := range vv {
|
||||
cc.Close()
|
||||
closeClientConn(cc)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Add table
Reference in a new issue