Skip to content

Commit

Permalink
Proper cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Nov 2, 2024
1 parent 82b33bc commit c2399f2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions x/examples/fetch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func main() {
return http.ErrUseLastResponse
},
}
defer httpClient.CloseIdleConnections()

var tlsConfig tls.Config
if *tlsKeyLogFlag != "" {
Expand Down Expand Up @@ -168,11 +169,11 @@ func main() {
slog.Error("Could not create PacketConn", "error", err)
os.Exit(1)
}
tr := &quic.Transport{
quicTransport := &quic.Transport{
Conn: conn,
}
defer tr.Close()
httpClient.Transport = &http3.Transport{
defer quicTransport.Close()
httpTransport := &http3.Transport{
TLSClientConfig: &tlsConfig,
Dial: func(ctx context.Context, addr string, tlsConf *tls.Config, quicConf *quic.Config) (quic.EarlyConnection, error) {
addressToDial, err := overrideAddress(addr, overrideHost, overridePort)
Expand All @@ -183,10 +184,12 @@ func main() {
if err != nil {
return nil, err
}
return tr.DialEarly(ctx, udpAddr, tlsConf, quicConf)
return quicTransport.DialEarly(ctx, udpAddr, tlsConf, quicConf)
},
Logger: slog.Default(),
}
defer httpTransport.Close()
httpClient.Transport = httpTransport
} else {
slog.Error("Invalid HTTP protocol", "proto", *protoFlag)
os.Exit(1)
Expand Down

0 comments on commit c2399f2

Please sign in to comment.