Go 1.8 and 1.9 use different text for the connection closed error.
Use their common prefix (i.e., "use of closed") in the tests for
them to pass on all Go versions.
Go 1.8: "use of closed network connection"
Go 1.9: "use of closed file or network connection"
Suggested-by: Damien Neil <dneil@google.com>
Retun as soon as we have the matched field in the HTTP2 matcher
regardless of weather the value is matched or not. Fixes#35.
Issue #35 reports that cmux leaks memory when the client is HTTP2
but does not sends the expected header field. For example, when
the non-gRPC client sends a large field in the header and we are
matching for gRPC, we waste a lot of memory in the sniff buffer.
After sniffing and buffering data, if we try to read from
the socket again, bufio.Reader may block. This breaks HTTP handlers
in go1.5.2+ if one tries on browsers or with curl. Go's HTTP client,
however, is not broken. This issue is also there with TeeReader.
Return immediately with the data in the sniffed buffer.
This commit closes the connections that has been buffered
on the connection channel of the cmux listeners, when the
root listener is closed. With this change it is guaranteed
that the connections are either closed or handed of to the
child listeners (returned via Accept()).
There are a couple of changes to the tests to cover corner
cases and the new behavior.
When the root listener is closed, child listeners will not be closed
until all parked connections are served. This prevents losing
connections that have been read from.
This also allows moving the main test to package cmux_test, but that
will happen in a separate change.
As reported in #4, when the root listener is closed, calling Accept
on mux'd listeners would block forever, instead of returning an error.
This is because of a bug introduced in b90740d.
This commit fixes#4 by selecting on both donec and connc of muxed
listeners.
Added a test case to guard against this issue.
If a matcher go-routine mateches a connection after the root
listener was closed, cmux will panic since all connection channels
will be closed. This commit avoids closing connection channels but
signals the matcher go-routines that the listener is closed via
a done channel.
Tested: Added a test case for this issue.