From 0a8622485862b5a026a267f643ce72f30ee8bd17 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 12 May 2019 13:45:40 +0900 Subject: [PATCH] pass a string, not an error, to Session.CloseWithError --- http3/client.go | 3 ++- http3/roundtrip_test.go | 4 ++-- interface.go | 4 ++-- internal/mocks/quic/session.go | 2 +- mock_quic_session_test.go | 2 +- session.go | 4 ++-- session_test.go | 4 ++-- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/http3/client.go b/http3/client.go index fc1008188..9f0e88311 100644 --- a/http3/client.go +++ b/http3/client.go @@ -87,7 +87,8 @@ func (c *client) dial() error { go func() { if err := c.setupSession(); err != nil { - c.session.CloseWithError(quic.ErrorCode(errorInternalError), err) + c.logger.Debugf("Setting up session failed: %s", err) + c.session.CloseWithError(quic.ErrorCode(errorInternalError), "") } }() diff --git a/http3/roundtrip_test.go b/http3/roundtrip_test.go index 79576beeb..c9e549c04 100644 --- a/http3/roundtrip_test.go +++ b/http3/roundtrip_test.go @@ -93,7 +93,7 @@ var _ = Describe("RoundTripper", func() { Expect(err).ToNot(HaveOccurred()) session.EXPECT().OpenUniStreamSync().AnyTimes().Return(nil, testErr) session.EXPECT().OpenStreamSync().Return(nil, testErr) - session.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(quic.ErrorCode, error) { close(closed) }) + session.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(quic.ErrorCode, string) { close(closed) }) _, err = rt.RoundTrip(req) Expect(err).To(MatchError(testErr)) Expect(rt.clients).To(HaveLen(1)) @@ -130,7 +130,7 @@ var _ = Describe("RoundTripper", func() { testErr := errors.New("test err") session.EXPECT().OpenUniStreamSync().AnyTimes().Return(nil, testErr) session.EXPECT().OpenStreamSync().Return(nil, testErr).Times(2) - session.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(quic.ErrorCode, error) { close(closed) }) + session.EXPECT().CloseWithError(gomock.Any(), gomock.Any()).Do(func(quic.ErrorCode, string) { close(closed) }) req, err := http.NewRequest("GET", "https://quic.clemente.io/file1.html", nil) Expect(err).ToNot(HaveOccurred()) _, err = rt.RoundTrip(req) diff --git a/interface.go b/interface.go index a83d09b84..1de307fa2 100644 --- a/interface.go +++ b/interface.go @@ -155,8 +155,8 @@ type Session interface { // Close the connection. io.Closer // Close the connection with an error. - // The error must not be nil. - CloseWithError(ErrorCode, error) error + // The error string will be sent to the peer. + CloseWithError(ErrorCode, string) error // The context is cancelled when the session is closed. // Warning: This API should not be considered stable and might change soon. Context() context.Context diff --git a/internal/mocks/quic/session.go b/internal/mocks/quic/session.go index 8ce290eb4..ae6c6b22b 100644 --- a/internal/mocks/quic/session.go +++ b/internal/mocks/quic/session.go @@ -83,7 +83,7 @@ func (mr *MockSessionMockRecorder) Close() *gomock.Call { } // CloseWithError mocks base method -func (m *MockSession) CloseWithError(arg0 protocol.ApplicationErrorCode, arg1 error) error { +func (m *MockSession) CloseWithError(arg0 protocol.ApplicationErrorCode, arg1 string) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CloseWithError", arg0, arg1) ret0, _ := ret[0].(error) diff --git a/mock_quic_session_test.go b/mock_quic_session_test.go index cb09527a1..833331885 100644 --- a/mock_quic_session_test.go +++ b/mock_quic_session_test.go @@ -82,7 +82,7 @@ func (mr *MockQuicSessionMockRecorder) Close() *gomock.Call { } // CloseWithError mocks base method -func (m *MockQuicSession) CloseWithError(arg0 protocol.ApplicationErrorCode, arg1 error) error { +func (m *MockQuicSession) CloseWithError(arg0 protocol.ApplicationErrorCode, arg1 string) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CloseWithError", arg0, arg1) ret0, _ := ret[0].(error) diff --git a/session.go b/session.go index 3d3fa44fa..2e8641fba 100644 --- a/session.go +++ b/session.go @@ -891,8 +891,8 @@ func (s *session) Close() error { return nil } -func (s *session) CloseWithError(code protocol.ApplicationErrorCode, e error) error { - s.closeLocal(qerr.Error(qerr.ErrorCode(code), e.Error())) +func (s *session) CloseWithError(code protocol.ApplicationErrorCode, desc string) error { + s.closeLocal(qerr.Error(qerr.ErrorCode(code), desc)) <-s.ctx.Done() return nil } diff --git a/session_test.go b/session_test.go index 13048d03b..c07520b54 100644 --- a/session_test.go +++ b/session_test.go @@ -405,7 +405,7 @@ var _ = Describe("Session", func() { sessionRunner.EXPECT().Retire(gomock.Any()) cryptoSetup.EXPECT().Close() packer.EXPECT().PackConnectionClose(gomock.Any()).Return(&packedPacket{}, nil) - sess.CloseWithError(0x1337, testErr) + sess.CloseWithError(0x1337, testErr.Error()) Eventually(areSessionsRunning).Should(BeFalse()) Expect(sess.Context().Done()).To(BeClosed()) }) @@ -1191,7 +1191,7 @@ var _ = Describe("Session", func() { sessionRunner.EXPECT().Retire(gomock.Any()) packer.EXPECT().PackConnectionClose(gomock.Any()).Return(&packedPacket{}, nil) cryptoSetup.EXPECT().Close() - Expect(sess.CloseWithError(0x1337, testErr)).To(Succeed()) + Expect(sess.CloseWithError(0x1337, testErr.Error())).To(Succeed()) Eventually(done).Should(BeClosed()) })