diff --git a/chain/chain.go b/chain/chain.go index 4a78fcb..458045a 100644 --- a/chain/chain.go +++ b/chain/chain.go @@ -104,7 +104,7 @@ func (c *Chain) Route(ctx context.Context, network, address string, opts ...chai tr.Options().Route = rt node = node.Copy() node.Options().Transport = tr - rt = NewRoute() + rt = NewRoute(ChainRouteOption(c)) } rt.addNode(node) diff --git a/chain/route.go b/chain/route.go index 4e176f1..c915a9b 100644 --- a/chain/route.go +++ b/chain/route.go @@ -129,10 +129,11 @@ func (r *route) connect(ctx context.Context, logger logger.Logger) (conn net.Con metrics.Labels{"chain": name, "node": node.Name}); v != nil { v.Inc() } - } else { - if marker != nil { - marker.Reset() - } + return + } + + if marker != nil { + marker.Reset() } } }() diff --git a/dialer/http2/dialer.go b/dialer/http2/dialer.go index fbee078..369640e 100644 --- a/dialer/http2/dialer.go +++ b/dialer/http2/dialer.go @@ -70,6 +70,19 @@ func (d *http2Dialer) Dial(ctx context.Context, address string, opts ...dialer.D 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{ Transport: &http.Transport{ 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) }, ForceAttemptHTTP2: true, - MaxIdleConns: 100, - IdleConnTimeout: 90 * time.Second, - TLSHandshakeTimeout: 10 * time.Second, - ExpectContinueTimeout: 1 * time.Second, + MaxIdleConns: 16, + IdleConnTimeout: 30 * time.Second, + TLSHandshakeTimeout: 30 * time.Second, + ExpectContinueTimeout: 15 * time.Second, }, } d.clients[address] = client } - var c net.Conn - c = &conn{ + var c net.Conn = &conn{ localAddr: &net.TCPAddr{}, remoteAddr: raddr, onClose: func() {