handle stream opening errors in h2quic client

This commit is contained in:
Marten Seemann
2017-02-22 15:29:18 +07:00
parent 8fd2ddf81c
commit 6f27b7f70d
3 changed files with 25 additions and 4 deletions

View File

@@ -69,8 +69,10 @@ func (c *Client) connStateCallback(sess quic.Session, state quic.ConnState) {
}
switch state {
case quic.ConnStateVersionNegotiated:
// TODO: handle errors
c.versionNegotiateCallback()
err := c.versionNegotiateCallback()
if err != nil {
c.Close(err)
}
case quic.ConnStateSecure:
c.encryptionLevel = protocol.EncryptionSecure
utils.Debugf("is secure")

View File

@@ -64,8 +64,7 @@ var _ = Describe("Client", func() {
})
It("opens the header stream only after the version has been negotiated", func() {
// delete the headerStream openend in the BeforeEach
client.headerStream = nil
client.headerStream = nil // unset the headerStream openend in the BeforeEach
session.streamToOpen = headerStream
Expect(client.headerStream).To(BeNil()) // header stream not yet opened
// now start the actual test
@@ -74,6 +73,22 @@ var _ = Describe("Client", func() {
Expect(client.headerStream.StreamID()).To(Equal(protocol.StreamID(3)))
})
It("errors if it can't open the header stream", func() {
testErr := errors.New("test error")
client.headerStream = nil // unset the headerStream openend in the BeforeEach
session.streamOpenErr = testErr
client.config.ConnState(session, quic.ConnStateVersionNegotiated)
Expect(session.closed).To(BeTrue())
Expect(session.closedWithError).To(MatchError(testErr))
})
It("errors if the header stream has the wrong StreamID", func() {
session.streamToOpen = &mockStream{id: 1337}
client.config.ConnState(session, quic.ConnStateVersionNegotiated)
Expect(session.closed).To(BeTrue())
Expect(session.closedWithError).To(MatchError("h2quic Client BUG: StreamID of Header Stream is not 3"))
})
It("sets the correct crypto level", func() {
Expect(client.encryptionLevel).To(Equal(protocol.Unencrypted))
client.config.ConnState(session, quic.ConnStateSecure)

View File

@@ -28,6 +28,7 @@ type mockSession struct {
dataStream quic.Stream
streamToAccept quic.Stream
streamToOpen quic.Stream
streamOpenErr error
}
func (s *mockSession) GetOrOpenStream(id protocol.StreamID) (quic.Stream, error) {
@@ -37,6 +38,9 @@ func (s *mockSession) AcceptStream() (quic.Stream, error) {
return s.streamToAccept, nil
}
func (s *mockSession) OpenStream() (quic.Stream, error) {
if s.streamOpenErr != nil {
return nil, s.streamOpenErr
}
return s.streamToOpen, nil
}
func (s *mockSession) OpenStreamSync() (quic.Stream, error) {