Skip to content

Commit 248747d

Browse files
committed
Fix issue with tls and http2.
1 parent 48d07f7 commit 248747d

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

  • libbeat/common/transport

libbeat/common/transport/tls.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,40 @@ func TestTLSDialerH2(
9393
config *tlscommon.TLSConfig,
9494
timeout time.Duration,
9595
) (DialerH2, error) {
96+
var lastTLSConfig *tls.Config
97+
var lastNetwork string
98+
var lastAddress string
99+
var m sync.Mutex
100+
96101
return DialerFuncH2(func(network, address string, cfg *tls.Config) (net.Conn, error) {
97102
switch network {
98103
case "tcp", "tcp4", "tcp6":
99104
default:
100105
return nil, fmt.Errorf("unsupported network type %v", network)
101106
}
102-
return tlsDialWith(d, forward, network, address, timeout, cfg, config)
107+
108+
host, _, err := net.SplitHostPort(address)
109+
if err != nil {
110+
return nil, err
111+
}
112+
113+
var tlsConfig *tls.Config
114+
m.Lock()
115+
if network == lastNetwork && address == lastAddress {
116+
tlsConfig = lastTLSConfig
117+
}
118+
if tlsConfig == nil {
119+
tlsConfig = config.BuildModuleClientConfig(host)
120+
lastNetwork = network
121+
lastAddress = address
122+
lastTLSConfig = tlsConfig
123+
}
124+
m.Unlock()
125+
126+
// NextProtos must be set from the passed h2 connection or it will fail
127+
tlsConfig.NextProtos = cfg.NextProtos
128+
129+
return tlsDialWith(d, forward, network, address, timeout, tlsConfig, config)
103130
}), nil
104131
}
105132

0 commit comments

Comments
 (0)