Skip to content

Commit

Permalink
Merge pull request #307 from Jigsaw-Code/fortuna-quic
Browse files Browse the repository at this point in the history
fix(x): properly cleanup the QUIC objects
  • Loading branch information
fortuna authored Nov 5, 2024
2 parents 82b33bc + c2399f2 commit ed096db
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 ed096db

Please sign in to comment.