The listener can be closed twice: in Close and in Serve. It might lead to
pretty bad things, for example, https://golang.org/src/net/unixsock_posix.go#L340
can delete a file which created by another listener.
Signed-off-by: Alexander Morozov <lk4d4math@gmail.com>
If server.Stop() and server.Serve() race, Serve() can return without
closing the listener. This in turn can lead to clients timing out trying
to connect to a server that is neither accepting nor rejecting
connections.
This simplifies the code that's used for wiring up the http.Handler-based
transport for testing. It's not used outside of tests.
http2.Server.ServeConn was added somewhat recently for other reasons and
I just realized it would simplify this code as well.
Move the test-only methods to a new internal package so as to not
pollute the godoc, and to prevent people from using them. (Packages
named internal or under internal are private, and enforced by the go
tool)
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 adds new http.Handler-based ServerTransport in the process,
reusing the HTTP/2 server code in x/net/http2 or Go 1.6+.
All end2end tests pass with this new ServerTransport.
Fixesgrpc/grpc-go#75
Also:
Updates grpc/grpc-go#495 (lets user fix it with middleware in front)
Updates grpc/grpc-go#468 (x/net/http2 validates)
Updates grpc/grpc-go#147 (possible with x/net/http2)
Updates grpc/grpc-go#104 (x/net/http2 does this)