forked from quic-go/quic-go
http3: reset stream when a handler panics (#4181)
* interrupt the stream when a panick happened * move the declaration of errPanicked * check what's read is a prefix of what's written * check errPanicked * use MatchError instead of Equal * use channel to notify the response has been received
This commit is contained in:
@@ -30,6 +30,7 @@ var (
|
||||
quicListenAddr = func(addr string, tlsConf *tls.Config, config *quic.Config) (QUICEarlyListener, error) {
|
||||
return quic.ListenAddrEarly(addr, tlsConf, config)
|
||||
}
|
||||
errPanicked = errors.New("panicked")
|
||||
)
|
||||
|
||||
// NextProtoH3 is the ALPN protocol negotiated during the TLS handshake, for QUIC v1 and v2.
|
||||
@@ -652,6 +653,11 @@ func (s *Server) handleRequest(conn quic.Connection, str quic.Stream, decoder *q
|
||||
}
|
||||
// If the EOF was read by the handler, CancelRead() is a no-op.
|
||||
str.CancelRead(quic.StreamErrorCode(ErrCodeNoError))
|
||||
|
||||
// abort the stream when there is a panic
|
||||
if panicked {
|
||||
return newStreamError(ErrCodeInternalError, errPanicked)
|
||||
}
|
||||
return requestError{}
|
||||
}
|
||||
|
||||
|
||||
@@ -272,7 +272,7 @@ var _ = Describe("Server", func() {
|
||||
str.EXPECT().CancelRead(gomock.Any())
|
||||
|
||||
serr := s.handleRequest(conn, str, qpackDecoder, nil)
|
||||
Expect(serr.err).ToNot(HaveOccurred())
|
||||
Expect(serr.err).To(MatchError(errPanicked))
|
||||
Expect(responseBuf.Bytes()).To(HaveLen(0))
|
||||
})
|
||||
|
||||
@@ -288,7 +288,7 @@ var _ = Describe("Server", func() {
|
||||
str.EXPECT().CancelRead(gomock.Any())
|
||||
|
||||
serr := s.handleRequest(conn, str, qpackDecoder, nil)
|
||||
Expect(serr.err).ToNot(HaveOccurred())
|
||||
Expect(serr.err).To(MatchError(errPanicked))
|
||||
Expect(responseBuf.Bytes()).To(HaveLen(0))
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user