fix: ensure pool's dial pass to client

This commit is contained in:
gVisor bot 2022-11-29 09:23:28 +08:00
parent 4f1c2dfbaa
commit 6c4a6872e7

View file

@ -22,6 +22,7 @@ type dialResult struct {
type PoolClient struct { type PoolClient struct {
*ClientOption *ClientOption
newClientOption *ClientOption
dialResultMap map[any]dialResult dialResultMap map[any]dialResult
dialResultMutex *sync.Mutex dialResultMutex *sync.Mutex
tcpClients *list.List[*Client] tcpClients *list.List[*Client]
@ -100,7 +101,7 @@ func (t *PoolClient) newClient(udp bool, opts ...dialer.Option) *Client {
clientsMutex.Lock() clientsMutex.Lock()
defer clientsMutex.Unlock() defer clientsMutex.Unlock()
client := NewClient(t.ClientOption, udp) client := NewClient(t.newClientOption, udp)
client.poolRef = t // make sure pool has a reference client.poolRef = t // make sure pool has a reference
client.optionRef = o client.optionRef = o
client.lastVisited = time.Now() client.lastVisited = time.Now()
@ -169,6 +170,9 @@ func NewClientPool(clientOption *ClientOption) *PoolClient {
udpClients: list.New[*Client](), udpClients: list.New[*Client](),
udpClientsMutex: &sync.Mutex{}, udpClientsMutex: &sync.Mutex{},
} }
newClientOption := *clientOption
newClientOption.DialFn = p.dial
p.newClientOption = &newClientOption
runtime.SetFinalizer(p, closeClientPool) runtime.SetFinalizer(p, closeClientPool)
return p return p
} }