mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-05-12 21:18:03 +08:00
fix: grpc transport can't be closed
This commit is contained in:
parent
23ffe451f4
commit
7f1225b0c4
35
transport/gun/transport_close.go
Normal file
35
transport/gun/transport_close.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package gun
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"golang.org/x/net/http2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type clientConnPool struct {
|
||||||
|
t *http2.Transport
|
||||||
|
mu sync.Mutex
|
||||||
|
conns map[string][]*http2.ClientConn // key is host:port
|
||||||
|
}
|
||||||
|
|
||||||
|
type efaceWords struct {
|
||||||
|
typ unsafe.Pointer
|
||||||
|
data unsafe.Pointer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tw *TransportWrap) Close() error {
|
||||||
|
connPool := transportConnPool(tw.Transport)
|
||||||
|
p := (*clientConnPool)((*efaceWords)(unsafe.Pointer(&connPool)).data)
|
||||||
|
p.mu.Lock()
|
||||||
|
defer p.mu.Unlock()
|
||||||
|
for _, vv := range p.conns {
|
||||||
|
for _, cc := range vv {
|
||||||
|
cc.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:linkname transportConnPool golang.org/x/net/http2.(*Transport).connPool
|
||||||
|
func transportConnPool(t *http2.Transport) http2.ClientConnPool
|
Loading…
Reference in New Issue
Block a user