Fix crashes where transports returned errors unhandled by the message parser.
The http.Handler-based transport body reader was returning error types not understood by the recvMsg parser. See #557 for some background and examples. Fix the http.Handler transport and add tests. I copied in a subset of the http2 package's serverTest type, adapted slightly to work with grpc. In the process of adding tests, I discovered that ErrUnexpectedEOF was also not handled by the regular server transport. Document the rules and fix that crash as well. Unrelated stuff in this CL: * make tests listen on localhost:0 instead of :0, to avoid Mac firewall pop-up dialogs. * rename parser.s field to parser.r, to be more idiomatic that it's an io.Reader and not anything fancier. (it's not acting like type stream, even if that's the typical concrete type) * move 5 byte temp buffer into parser, rather than allocating it for each new message. (drop in the bucket improvement in garbage; more to do later) * rename http2RSTErrConvTab to http2ErrConvTab, per Qi's earlier CL. Also add the HTTP/1.1-required error mapping for completeness, not that it should ever arise with gRPC, also per Qi's earlier CL referenced in #557.
This commit is contained in:
@ -65,7 +65,7 @@ func TestSimpleParsing(t *testing.T) {
|
||||
{append([]byte{0, 1, 0, 0, 0}, bigMsg...), nil, bigMsg, compressionNone},
|
||||
} {
|
||||
buf := bytes.NewReader(test.p)
|
||||
parser := &parser{buf}
|
||||
parser := &parser{r: buf}
|
||||
pt, b, err := parser.recvMsg()
|
||||
if err != test.err || !bytes.Equal(b, test.b) || pt != test.pt {
|
||||
t.Fatalf("parser{%v}.recvMsg() = %v, %v, %v\nwant %v, %v, %v", test.p, pt, b, err, test.pt, test.b, test.err)
|
||||
@ -77,7 +77,7 @@ func TestMultipleParsing(t *testing.T) {
|
||||
// Set a byte stream consists of 3 messages with their headers.
|
||||
p := []byte{0, 0, 0, 0, 1, 'a', 0, 0, 0, 0, 2, 'b', 'c', 0, 0, 0, 0, 1, 'd'}
|
||||
b := bytes.NewReader(p)
|
||||
parser := &parser{b}
|
||||
parser := &parser{r: b}
|
||||
|
||||
wantRecvs := []struct {
|
||||
pt payloadFormat
|
||||
|
||||
Reference in New Issue
Block a user