fix marker for selector

This commit is contained in:
ginuerzh 2024-06-07 20:57:47 +08:00
parent 118ee91c95
commit ce60160cd7
3 changed files with 24 additions and 11 deletions

View File

@ -104,7 +104,7 @@ func (c *Chain) Route(ctx context.Context, network, address string, opts ...chai
tr.Options().Route = rt tr.Options().Route = rt
node = node.Copy() node = node.Copy()
node.Options().Transport = tr node.Options().Transport = tr
rt = NewRoute() rt = NewRoute(ChainRouteOption(c))
} }
rt.addNode(node) rt.addNode(node)

View File

@ -129,12 +129,13 @@ func (r *route) connect(ctx context.Context, logger logger.Logger) (conn net.Con
metrics.Labels{"chain": name, "node": node.Name}); v != nil { metrics.Labels{"chain": name, "node": node.Name}); v != nil {
v.Inc() v.Inc()
} }
} else { return
}
if marker != nil { if marker != nil {
marker.Reset() marker.Reset()
} }
} }
}
}() }()
addr, err := chain.Resolve(ctx, network, node.Addr, node.Options().Resolver, node.Options().HostMapper, logger) addr, err := chain.Resolve(ctx, network, node.Addr, node.Options().Resolver, node.Options().HostMapper, logger)

View File

@ -70,6 +70,19 @@ func (d *http2Dialer) Dial(ctx context.Context, address string, opts ...dialer.D
opt(&options) opt(&options)
} }
{
// Check whether the connection is established properly
netd := options.NetDialer
if netd == nil {
netd = net_dialer.DefaultNetDialer
}
conn, err := netd.Dial(ctx, "tcp", address)
if err != nil {
return nil, err
}
conn.Close()
}
client = &http.Client{ client = &http.Client{
Transport: &http.Transport{ Transport: &http.Transport{
TLSClientConfig: d.options.TLSConfig, TLSClientConfig: d.options.TLSConfig,
@ -81,17 +94,16 @@ func (d *http2Dialer) Dial(ctx context.Context, address string, opts ...dialer.D
return netd.Dial(ctx, network, addr) return netd.Dial(ctx, network, addr)
}, },
ForceAttemptHTTP2: true, ForceAttemptHTTP2: true,
MaxIdleConns: 100, MaxIdleConns: 16,
IdleConnTimeout: 90 * time.Second, IdleConnTimeout: 30 * time.Second,
TLSHandshakeTimeout: 10 * time.Second, TLSHandshakeTimeout: 30 * time.Second,
ExpectContinueTimeout: 1 * time.Second, ExpectContinueTimeout: 15 * time.Second,
}, },
} }
d.clients[address] = client d.clients[address] = client
} }
var c net.Conn var c net.Conn = &conn{
c = &conn{
localAddr: &net.TCPAddr{}, localAddr: &net.TCPAddr{},
remoteAddr: raddr, remoteAddr: raddr,
onClose: func() { onClose: func() {