New connections can race with GracefulStop such that the server will accept the connection, but then close it immediately. If a connection is accepted before GracefulStop has a chance to effectively cancel the listeners, the server should handle it to avoid client errors.
The parent ClientConn should re-resolve when grpclb loses connection to the
remote balancer.
When the ClientConn inside grpclb gets a TransientFailure, it calls
lbManualResolver.ResolveNow(), which calls parent ClientConn's ResolveNow, and
eventually results in re-resolve happening in parent ClientConn's resolver (DNS
for example).
This PR adds a method to balancer.ClientConn interface, so balancer can tell
parent ClientConn to re-resolve.
WithBalancerName dial option specifies the name of the balancer to be used by the ClientConn. Service config updates can NOT override the balancer option.
1. Call transport Close if newHTTP2Server returns non-nil error.
Handle ConnBegin was called before this error, and handle ConnEnd is not called (because Close() is not called), which caused ConnStats check to fail.
2. Skip stats test in go1.6.
go1.6 doesn't have DialContext (we use Dialer(Cancel: ctx.Done()) instead). When the give context is canceled, this function sometimes returns canceled error, while the server side still gets the conn. This caused the server blocking on reading the preface (which will eventually timeout, but the tests are too short for that), and there will be a missing ConnEnd.
"go1.6, !go1.8" constraints are interpreted as (version >= 1.6 AND ) OR version < 1.8, where (version >= 1.6 AND ) is always false,
so it matches all go versions before 1.8, not only 1.6 and 1.7.
Removed a space, so the constraints are now matches only go1.6 and go1.7 versions
Split round_robin balancer into a base balancer (which manages SubConn and connectivity states), and a round_robin picker.
A custom picker with other picking algorithms can be provided to build custom balancers.
* protoCodec: return early if proto.Marshaler
If the object to marshal implements proto.Marshaler, delegate to that
immediately instead of pre-allocating a buffer. (*proto.Buffer).Marshal
has the same logic, so the []byte buffer we pre-allocate in codec.go
would never be used.
This is mainly for users of gogoproto. If you turn on the "marshaler"
and "sizer" gogoproto options, the generated Marshal() method already
pre-allocates a buffer of the appropriate size for marshaling the
entire object.
* protoCodec: return early if proto.Unmarshaler
If the object to unmarshal implements proto.Unmarshaler, delegate to
that immediately. This perhaps saves a bit of work preparing the
cached the proto.Buffer object which would not end up being used for
the proto.Unmarshaler case.
Note that I moved the obj.Reset() call above the delegation to
obj.Unmarshal(). This maintains the grpc behavior of
proto.Unmarshalers always being Reset() before being delegated to,
which is consistent to how proto.Unmarshal() behaves (proto.Buffer
does not call Reset() in Unmarshal).
WriteStatus can be called concurrently: one by SendMsg,
the other by RecvMsg. Then, closing writes channel
becomes racey without proper locking.
Make transport closing synchronous in such case.
This allows ClientConn to get more up-to-date addresses from resolver.
ClientConn compares new addresses with the cached ones. So if resolver returns the same set of addresses, ClientConn will not notify balancer about it.
Also moved the initialization of resolver and balancer to avoid race. Balancer will only be started when ClientConn gets resolved addresses from balancer.