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.
This commit is contained in:
Lorenzo Saino 2020-02-23 00:21:19 +00:00
parent f5d88d3edd
commit 8db2288382
2 changed files with 9 additions and 0 deletions

View file

@ -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), "")
}

View file

@ -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