@@ -279,7 +279,7 @@ func (doq *dnsOverQUIC) openStream(ctx context.Context, conn *quic.Conn) (*quic.
279279}
280280
281281// openConnection opens a new QUIC connection.
282- func (doq * dnsOverQUIC ) openConnection (ctx context.Context ) (conn * quic.Conn , err error ) {
282+ func (doq * dnsOverQUIC ) openConnection (ctx context.Context ) (quicConn * quic.Conn , err error ) {
283283 // we're using bootstrapped address instead of what's passed to the function
284284 // it does not create an actual connection, but it helps us determine
285285 // what IP is actually reachable (when there're v4/v6 addresses).
@@ -298,7 +298,7 @@ func (doq *dnsOverQUIC) openConnection(ctx context.Context) (conn *quic.Conn, er
298298
299299 p , err := strconv .Atoi (port )
300300 udpAddr := net.UDPAddr {IP : net .ParseIP (ip ), Port : p }
301- udp , err := doq .dialer .ListenPacket (ctx , "udp" , addr )
301+ packetConn , err := doq .dialer .ListenPacket (ctx , "udp" , addr )
302302 if err != nil {
303303 return nil , err
304304 }
@@ -322,15 +322,16 @@ func (doq *dnsOverQUIC) openConnection(ctx context.Context) (conn *quic.Conn, er
322322 return nil , err
323323 }
324324
325- transport := quic.Transport {Conn : udp }
325+ transport := quic.Transport {Conn : packetConn }
326326 transport .SetCreatedConn (true ) // auto close conn
327327 transport .SetSingleUse (true ) // auto close transport
328- conn , err = transport .Dial (ctx , & udpAddr , tlsConfig , doq .getQUICConfig ())
328+ quicConn , err = transport .Dial (ctx , & udpAddr , tlsConfig , doq .getQUICConfig ())
329329 if err != nil {
330+ _ = packetConn .Close ()
330331 return nil , fmt .Errorf ("opening quic connection to %s: %w" , doq .addr , err )
331332 }
332333
333- return conn , nil
334+ return quicConn , nil
334335}
335336
336337// closeConnWithError closes the active connection with error to make sure that
0 commit comments