From 8db2288382bc5c5679594e38ad4ed5ac438c739f Mon Sep 17 00:00:00 2001 From: Lorenzo Saino Date: Sun, 23 Feb 2020 00:21:19 +0000 Subject: [PATCH] Make http3.client.Close() succeed if session was not started Invoking http3.client.Close() before client.dial() is invoked causes a segmentation fault. That occurs because, in this circumstance, invoking client.Close() results in invoking client.session.CloseWithError(...) while client.session is nil. This commit changes the behavior of http3.client.Close() to return nil if client.session is nil and adds an associated test case. --- http3/client.go | 3 +++ http3/client_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/http3/client.go b/http3/client.go index f5ae8332..3a5df255 100644 --- a/http3/client.go +++ b/http3/client.go @@ -127,6 +127,9 @@ func (c *client) setupSession() error { } func (c *client) Close() error { + if c.session == nil { + return nil + } return c.session.CloseWithError(quic.ErrorCode(errorNoError), "") } diff --git a/http3/client_test.go b/http3/client_test.go index 8b2dee27..4f1e2296 100644 --- a/http3/client_test.go +++ b/http3/client_test.go @@ -146,6 +146,12 @@ var _ = Describe("Client", func() { Expect(err).To(MatchError(testErr)) }) + It("closes correctly if session was not created", func() { + client = newClient("localhost:1337", nil, &roundTripperOpts{}, nil, nil) + err := client.Close() + Expect(err).ToNot(HaveOccurred()) + }) + Context("Doing requests", func() { var ( request *http.Request