Aetherance commented on code in PR #3086:
URL: https://github.com/apache/dubbo-go/pull/3086#discussion_r2616841970
##########
protocol/triple/client.go:
##########
@@ -213,111 +246,88 @@ func newClientManager(url *common.URL) (*clientManager,
error) {
callProtocol = constant.CallHTTP2
}
+ transport, err := buildTransport(callProtocol, cfg, keepAliveInterval,
keepAliveTimeout, tlsFlag)
+ if err != nil {
+ return nil, err
+ }
+ httpClient := &http.Client{
+ Transport: transport,
+ }
+ perClientTransport := url.GetParamBool("tri.per_client_transport",
false)
+
+ var baseTriURL string
+ baseTriURL = strings.TrimPrefix(url.Location, httpPrefix)
+ baseTriURL = strings.TrimPrefix(baseTriURL, httpsPrefix)
+ if tlsFlag {
+ baseTriURL = httpsPrefix + baseTriURL
+ } else {
+ baseTriURL = httpPrefix + baseTriURL
+ }
+
+ triURL, err := joinPath(baseTriURL, url.Interface())
+ if err != nil {
+ return nil, fmt.Errorf("JoinPath failed for base %s, interface
%s", baseTriURL, url.Interface())
+ }
+
+ pool := NewTriClientPool(constant.DefaultClientWarmingUp,
constant.TriClientPoolMaxSize, func() *tri.Client {
+ if perClientTransport {
+ dedicatedTransport, buildErr :=
buildTransport(callProtocol, cfg, keepAliveInterval, keepAliveTimeout, tlsFlag)
+ if buildErr != nil {
+ return tri.NewClient(httpClient, triURL,
cliOpts...)
+ }
+ return tri.NewClient(&http.Client{Transport:
dedicatedTransport}, triURL, cliOpts...)
+ }
+ return tri.NewClient(httpClient, triURL, cliOpts...)
+ })
+
+ return &clientManager{
+ isIDL: isIDL,
+ triGuard: &sync.RWMutex{},
+ triClients: pool,
+ }, nil
+}
+
+func buildTransport(callProtocol string, cfg *tls.Config, keepAliveInterval,
keepAliveTimeout time.Duration, tlsFlag bool) (http.RoundTripper, error) {
switch callProtocol {
- // This case might be for backward compatibility,
- // it's not useful for the Triple protocol, HTTP/1 lacks trailer
functionality.
- // Triple protocol only supports HTTP/2 and HTTP/3.
case constant.CallHTTP:
- transport = &http.Transport{
+ return &http.Transport{
TLSClientConfig: cfg,
- }
- cliOpts = append(cliOpts, tri.WithTriple())
+ }, nil
case constant.CallHTTP2:
- // TODO: Enrich the http2 transport config for triple protocol.
if tlsFlag {
- transport = &http2.Transport{
+ return &http2.Transport{
TLSClientConfig: cfg,
ReadIdleTimeout: keepAliveInterval,
PingTimeout: keepAliveTimeout,
- }
- } else {
- transport = &http2.Transport{
- DialTLSContext: func(_ context.Context,
network, addr string, _ *tls.Config) (net.Conn, error) {
- return net.Dial(network, addr)
- },
- AllowHTTP: true,
- ReadIdleTimeout: keepAliveInterval,
- PingTimeout: keepAliveTimeout,
- }
+ }, nil
}
+ return &http2.Transport{
+ DialTLSContext: func(_ context.Context, network, addr
string, _ *tls.Config) (net.Conn, error) {
+ return net.Dial(network, addr)
+ },
+ AllowHTTP: true,
+ ReadIdleTimeout: keepAliveInterval,
+ PingTimeout: keepAliveTimeout,
+ }, nil
case constant.CallHTTP3:
if !tlsFlag {
return nil, fmt.Errorf("TRIPLE http3 client must have
TLS config, but TLS config is nil")
}
-
- // TODO: Enrich the http3 transport config for triple protocol.
- transport = &http3.Transport{
+ return &http3.Transport{
TLSClientConfig: cfg,
QUICConfig: &quic.Config{
- // ref:
https://quic-go.net/docs/quic/connection/#keeping-a-connection-alive
KeepAlivePeriod: keepAliveInterval,
- // ref:
https://quic-go.net/docs/quic/connection/#idle-timeout
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]