cleanup(quic): wait for handshake completion in netxlite (#729)
See https://github.com/ooni/probe/issues/2097
This commit is contained in:
parent
5904e6988d
commit
2238908afe
6 changed files with 140 additions and 102 deletions
|
|
@ -55,9 +55,12 @@ func NewQUICDialerWithResolver(listener model.QUICListener,
|
|||
Dialer: &quicDialerResolver{
|
||||
Dialer: &quicDialerLogger{
|
||||
Dialer: &quicDialerErrWrapper{
|
||||
QUICDialer: &quicDialerQUICGo{
|
||||
QUICListener: listener,
|
||||
}},
|
||||
QUICDialer: &quicDialerHandshakeCompleter{
|
||||
Dialer: &quicDialerQUICGo{
|
||||
QUICListener: listener,
|
||||
},
|
||||
},
|
||||
},
|
||||
Logger: logger,
|
||||
operationSuffix: "_address",
|
||||
},
|
||||
|
|
@ -164,6 +167,33 @@ func (d *quicDialerQUICGo) CloseIdleConnections() {
|
|||
// nothing to do
|
||||
}
|
||||
|
||||
// quicDialerHandshakeCompleter ensures we complete the handshake.
|
||||
type quicDialerHandshakeCompleter struct {
|
||||
Dialer model.QUICDialer
|
||||
}
|
||||
|
||||
// DialContext implements model.QUICDialer.DialContext.
|
||||
func (d *quicDialerHandshakeCompleter) DialContext(
|
||||
ctx context.Context, network, address string,
|
||||
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) {
|
||||
conn, err := d.Dialer.DialContext(ctx, network, address, tlsConfig, quicConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
select {
|
||||
case <-conn.HandshakeComplete().Done():
|
||||
return conn, nil
|
||||
case <-ctx.Done():
|
||||
conn.CloseWithError(0, "") // we own the conn
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
// CloseIdleConnections implements model.QUICDialer.CloseIdleConnections.
|
||||
func (d *quicDialerHandshakeCompleter) CloseIdleConnections() {
|
||||
d.Dialer.CloseIdleConnections()
|
||||
}
|
||||
|
||||
// quicConnectionOwnsConn ensures that we close the UDPLikeConn.
|
||||
type quicConnectionOwnsConn struct {
|
||||
// EarlyConnection is the embedded early connection
|
||||
|
|
|
|||
Loading…
Reference in a new issue