Commit Graph

255 Commits

Author SHA1 Message Date
Kun Zhang d86dfc9552 Merge DelayedStream's setError() into cancel()
DelayedClientTransport.PendingStream will override cancel(), which has a
clearer semantic.

Also permitting all status codes except OK in ClientStream.cancel(),
instead of just 4 codes.
2016-02-25 11:28:48 -08:00
nmittler 86fd2523ec Update to latest netty and tcnative. 2016-02-20 14:50:06 -08:00
nmittler 5cef321b78 Use Netty's StreamBufferingEncoder
Fixes #1060
2016-02-19 11:29:28 -08:00
Trask Stalnaker c10f5781b9 Fix sporadic NullPointerException
Fixes #1426
2016-02-18 21:43:43 -08:00
Eric Anderson 8d43880356 hpack is no longer a direct dependency
It isn't even a dependency of Netty, now that Netty has forked the code.
2016-02-16 14:54:17 -08:00
Eric Anderson b752e76858 Automated readability/efficiency tweaks
Although the changes were determined automatically, they were manually
applied to the codebase.

ClientCalls actually has a bug fix, since the suggestion to add
interrupt() made it obvious that interrupted() was inappropriate.
2016-02-16 14:15:23 -08:00
Eric Anderson a3303b51ec Delete unused CancelStreamCommand 2016-02-16 11:45:29 -08:00
Carl Mastrangelo 2d2398ce3a d'oh, really raise the visibility 2016-02-16 10:55:24 -08:00
Carl Mastrangelo acdcd5b114 Raise visibility of netty Channel Builder, and provide a way to pass in a custom protocol negotiator per transport 2016-02-16 10:39:20 -08:00
Kun Zhang cf787bddf2 DelayedClientTransport and fix TransportSet.shutdown() semantics.
Always return a completed future from `TransportSet`. If a (real) transport has not been created (e.g., in reconnect back-off), a `DelayedClientTransport` will be returned.

Eventually we will get rid of the transport futures everywhere, and have streams always __owned__ by some transports.

DelayedClientTransport
----------------------

After we get rid of the transport future, this is what `ClientCallImpl` and `LoadBalancer` get when a real transport has not been created yet. It buffers new streams and pings until `setTransport()` is called, after which point all buffered and future streams/pings are transferred to the real transport.

If a buffered stream is cancelled, `DelayedClientTransport` will remove it from the buffer list, thus #1342 will be resolved after the larger refactoring is complete.

This PR only makes `TransportSet` use `DelayedClientTransport`. Follow-up changes will be made to allow `LoadBalancer.pickTransport()` to return null, in which case `ManagedChannelImpl` will give `ClientCallImpl` a `DelayedClientTransport`.

Changes to ClientTransport shutdown semantics
---------------------------------------------

Previously when shutdown() is called, `ClientTransport` should not accept newStream(), and when all existing streams have been closed, `ClientTransport` is terminated. Only when a transport is terminated would a transport owner (e.g., `TransportSet`) remove the reference to it.

`DelayedClientTransport` brings about a new case: when `setTransport()` is called, we switch to the real transport and no longer need the delayed transport. This is achieved by calling `shutdown()` on the delayed transport and letting it terminate. However, as the delayed transport has already been handed out to users, we would like `newStream()` to keep working for them, even though the delayed transport is already shut down and terminated.

In order to make it easy to manage the life-cycle of `DelayedClientTransport`, we redefine the shutdown semantics of transport:
- A transport can own a stream. Typically the transport owns the streams
  it creates, but there may be exceptions. `DelayedClientTransport` DOES
  NOT OWN the streams it returns from `newStream()` after `setTransport()`
  has been called. Instead, the ownership would be transferred to the
  real transport.
- After `shutdown()` has been called, the transport stops owning new
  streams, and `newStream()` may still succeed. With this idea,
  `DelayedClientTransport`, even when terminated, will continue
  passing `newStream()` to the real transport.
- When a transport is in shutdown state, and it doesn't own any stream,
  it then can enter terminated state.

ManagedClientTransport / ClientTransport
----------------------------------------

Remove life-cycle interfaces from `ClientTransport`, and put them in its subclass - `ManagedClientTransport`, with the same idea that we have `Channel` and `ManagedChannel`. Only the one who creates the transport will get `ManagedClientTransport` thus is able to start and shutdown the transport. The users of transport, e.g., `LoadBalancer`, can only get `ClientTransport` thus are not alter its state. This change clarifies the responsibility of transport life-cycle management.

Fix TransportSet shutdown semantics
-----------------------------------

Currently, if `TransportSet.shutdown()` has been called, it no longer create new transports, which is wrong.

The correct semantics of `TransportSet.shutdown()` should be:
- Shutdown all transports, thus stop new streams being created on them
- Stop `obtainActiveTransport()` from returning transports
- Streams that already created, including those buffered in delayed transport, should continue. That means if delayed transport has buffered streams, we should let the existing reconnect task continue.
2016-02-12 09:36:25 -08:00
Eric Anderson 964963ab1a Replace AUTHORITY_KEY with ClientStream.setAuthority 2016-02-10 17:26:51 -08:00
Carl Mastrangelo 3f9e486e0d Raise visibility of Netty Channel Builder Ctor 2016-02-10 10:52:18 -08:00
Eric Anderson 5b9726ea7d netty: release buffered objects when failed
Releasing on failure prevents memory leak.

Fixes #1401
2016-02-10 09:36:54 -08:00
Eric Anderson 3d3fd11378 Negotiation Handlers should implement ChannelHandler
Having Handler implement ChannelInboundHandler is overspecifying and
unnecessary, as the code compiles fine just by changing "implements
ChannelInboundHandler" to "implements ChannelHandler".

PlaintextHandler was swapped to ChannelHandlerAdapter instead of
ChannelDuplexHandler because it just needs the ChannelHandler methods.
2016-02-04 14:02:57 -08:00
Carl Mastrangelo 04a6c8395b Remove deprecated call and TODO in Protocol negotiators 2016-02-04 13:39:56 -08:00
Eric Anderson 7e3d0fe9cc Mark ChannelHandler.exceptionCaught implementation deprecated to fix warning
This just propagates the deprecated annotation from ChannelHandler. Note
that exceptionCaught is _not_ deprecated for ChannelInboundHandler and
ChannelDuplexHandler.
2016-02-01 13:14:13 -08:00
Carl Mastrangelo a3c79e87ae Add a simple compression API 2016-02-01 12:56:21 -08:00
Carl Mastrangelo ba4a6ca47b Update to netty 4.1.0.CR1 2016-01-29 17:55:18 -08:00
nmittler 70ef5b1172 Make handling of GoAwayClosedStreamException more consistent. 2016-01-26 11:39:06 -08:00
Carl Mastrangelo 0486af6a88 Raise method visibility in Channel Providers 2016-01-14 11:12:53 -08:00
Eric Anderson bcb5fcdf82 Propagate headers/trailers if response isn't gRPC
This provides more structured data into the application for it to do
special handling.

In general, we would hope most people don't need this functionality, but
it is a good escape hatch to allow users to workaround infrastructure
problems.
2016-01-13 18:27:16 -08:00
Eric Anderson 9cb79292aa Add toString to transports for debugging.
This is a partial re-application of eca1f7c, but using super.toString()
to distinguish different transports that go to the same endpoint.
2016-01-12 11:28:40 -08:00
Eric Anderson 218865a19e Revert "More information for debugging."
This reverts commit eca1f7c1d6.

We want to preserve the status message identical to what the server
sent. We'll need a better way to communicate debugging details.
2016-01-11 16:35:43 -08:00
Carl Mastrangelo 3276442d4e Split newStream from start 2016-01-06 11:46:24 -08:00
Kun Zhang eca1f7c1d6 More information for debugging.
- Include transport information in RPC's final status
- Implement toString() of transports
2016-01-05 12:29:26 -08:00
Carl Mastrangelo d3d8adbab6 Allow support for nanosecond timeouts, and use nanoseconds consistently throughout our code 2015-12-17 18:22:47 -08:00
Carl Mastrangelo b9cacc1553 update tests 2015-12-14 16:09:28 -08:00
Carl Mastrangelo 82a79d8f93 Expose compression on ClientCall and Server Call 2015-12-08 10:49:27 -08:00
Eric Anderson 96f9cefda4 Close active streams on channelInactive
We think this broke when the stream lifecycle listener was removed.
Observing the stream lifecycle would be the "proper" fix, but it had
notification ordering issues where streams would close before we were
notified of the event that caused the closure, which made it difficult
to provide useful error messages. The ordering of notifications was also
largely undefined.

The long term fix we look forward to is the HTTP/2 child channels, which
should have clearly defined ordering between error notification and
channel closure, and in the order that we need here.

Fixes #1251
2015-12-07 09:00:41 -08:00
Louis Ryan be6008666e Initial basic implementation of context binding for clients with some limited testing
Adds utility functions for working with Contexts and interceptors
Use 'name' as Context.Key.toString to make conversion to Metadata simpler
2015-12-02 15:33:58 -08:00
Eric Anderson 2db02b52be Reduce advertised Netty API
NettyServer wasn't usable as public, since its constructor was
package-private. So although this reduces our API, it shouldn't actually
impact anyone.

Fixes #1047
2015-11-25 14:12:10 -08:00
Eric Anderson 7ba9ca4861 Map IOException during connecting to UNAVAILABLE
This isn't expected to have much impact once the connection is
established because AbstractNettyHandler.exceptionCaught() wraps all
unknown exceptions with Http2Exception. Fixing that is future work.

Some cases we may now be unwrapping a StatusException, such as one
thrown by MessageDeframer. In general, that seems a Good Thing™, but it
is unclear exactly if it would be perceivable.

Fixes #1181
2015-11-25 09:43:38 -08:00
nmittler 61a0d8238f Auto-refill connection window
Fixes #1175
2015-11-24 10:24:00 -08:00
Carl Mastrangelo 7de6c04d14 Move decompressor setting to the AbstractServerStream 2015-11-20 13:27:27 -08:00
Jakob Buchgraber e8afcb47ff Fix build failure due to unused import. 2015-11-19 14:26:09 +01:00
nmittler ebed5a624a Upgrading to Netty 4.1.0.Beta8
A few things to note:

- ByteString has gone away in favor of AsciiString.

- Http2Headers now uses CharSequence for all methods, so there are a few places that we have to explicitly check for AsciiString to get the optimizations.

- We now have to specify a graceful shutdown timeout for our Netty handlers. Using 5 seconds.
2015-11-18 11:42:24 -08:00
Eric Anderson 76eaae26b8 Enable LB and Naming for Netty.forAddress(String,int)
This swaps to the forTarget() codepath. The constructor is to make it
more convenient when extending the builder to disable checkAuthority.
2015-11-13 19:30:21 -08:00
Carl Mastrangelo 2ad35b8269 Add Header name character restrictions 2015-11-10 11:20:04 -08:00
nmittler 8c7e251f41 Allow Netty server override for ProtocolNegotiator
Server implementation had to be refactored to use a ProtocolNegotiator to make this work.
2015-11-02 13:04:37 -08:00
nmittler e775885be2 Allow client to specify ProtocolNegotiator in NettyChannelBuilder. 2015-11-02 09:02:41 -08:00
nmittler b9195fb9aa Set connectionWindow to MAX_INT.
This is a temporary fix for https://github.com/grpc/grpc-java/issues/1175. We will revisit this change after auto-refill is supported in Netty.
2015-10-30 12:29:31 -07:00
Xudong Ma 750b1977ca Make the header list size limit configurable on both client and server side. 2015-10-30 10:52:47 -07:00
nmittler 23e2df9a67 Allowing AbstractBufferingHandler to be extended. 2015-10-29 11:06:09 -07:00
Carl Mastrangelo c53b5170ca Downgrade mockito, and fix tests 2015-10-28 12:57:10 -07:00
nmittler 3efc61b237 Guard against NPE in Netty handlers
We've seen an NPE as a side-effect of a failure in protocol negotiation:

Oct 27, 2015 9:27:09 PM io.grpc.transport.netty.ProtocolNegotiators$AbstractBufferingHandler fail
SEVERE: Transport failed during protocol negotiation
java.lang.NullPointerException
	at io.grpc.transport.netty.NettyClientHandler$2.visit(NettyClientHandler.java:218)
2015-10-28 08:38:59 -07:00
Kun Zhang edd57c941e Support default port in NameResolver.
- Channel builders decide the default port based on whether TLS is used.
- Channel builders populate the default port via an Attributes object
  passed to NameResolver.Factory#newNameResolver
2015-10-27 13:54:36 -07:00
Carl Mastrangelo db56c2463e Add followup ProtocolNegotiators.tls tests 2015-10-26 12:19:07 -07:00
Carl Mastrangelo dd815bc968 Add initial Protocol Negotiation tests 2015-10-26 11:46:52 -07:00
nmittler 6f64999821 Addressing concurrency issue in MessageFramer.
Fixes (hopefully): #991
2015-10-23 13:00:23 -07:00
Kun Zhang efac679abc NameResolverRegistry and better-defined target string.
- NameResolverRegistry contains all the official NameResolvers. Users
  can also add custom NameResolvers to it. It looks up NameResolver by
  try-and-fail. It is the default NameResolver.Factory for builders.
  DnsNameResolver.
- Pass target as Strings instead of URIs from the channel builder to
  ManagedChannelImpl. A target string is not necessarily a valid URI, in
  which case ManagedChannelImpl will add "dns:///" to the beginning of
  the target and use it as URI.
- DnsNameResolver will require scheme "dns" to be present. It no longer
  allows scheme-absent URIs.
2015-10-23 09:37:22 -07:00