Commit Graph

217 Commits

Author SHA1 Message Date
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 0486af6a88 Raise method visibility in Channel Providers 2016-01-14 11:12:53 -08:00
Carl Mastrangelo 846794e578 Fix OkHttp bug where streams could be started after they had been cancelled 2016-01-13 18:41: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
Xudong Ma d948330ef2 [OkHttp]Add hostname verification. 2015-12-21 11:30:02 -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
Xudong Ma d41a0fa38e Use getClassLoader() instead of Thread.currentThread().getContextClassLoader() for android.
See #1272 for more details.
2015-12-10 15:06:47 -08:00
Xudong Ma 88491c064f [okhttp] Use upper layer passed-in resolved address instead of resolving the hostname by itself. 2015-11-25 16:48:58 -08:00
Xudong Ma 097e3a8c65 coalesce pending flushes in OkHttpClientStream.start(). 2015-11-25 16:44:08 -08:00
Carl Mastrangelo e9c9d31704 Add even more coverage 2015-11-09 12:35:24 -08:00
Carl Mastrangelo a691752165 Add simple tests for OkHttpProtocolNegotiator coverage 2015-11-06 13:15:28 -08:00
Xudong Ma 52c9aac1c1 [OkHtpp] Correct windowUpdateWithInboundFlowControl test. 2015-10-29 08:52:57 -07:00
Xudong Ma a2216f665a Deflake OkHttpClientTransportTest. 2015-10-27 14:26:36 -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 5487c42713 Update okhttp javadoc 2015-10-27 10:10:35 -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
Kun Zhang 942f4c99d8 Load-balancing ManagedChannelImpl.
- Add NameResolver and LoadBalancer interfaces.
- ManagedChannelImpl now uses NameResolver and LoadBalancer for
  transport selection, which may return transports to multiple
  addresses.
- Transports are still owned by ManagedChannelImpl, which implements
  TransportManager interface that is provided to LoadBalancer, so that
  LoadBalancer doesn't worry about Transport lifecycles.
- Channel builders can be created by forTarget() that accepts the fully
  qualified target name, which is an URI. (TODO) it's not tested.
- The old address-based construction pattern is supported by using
  AbstractManagedChannelImplBuilder.DirectAddressNameResolver.
- (TODO) DnsNameResolver and SimpleLoadBalancer are currently
  incomplete. They merely work for the single-address scenario.
2015-10-20 17:28:44 -07:00
Xudong Ma b121c46b42 Reduce OkHttp dependency, copy all the needed files into our repository. 2015-10-15 16:35:08 -07:00
Xudong Ma 6d296e84b6 Upgrade OkHttp to 2.5 2015-10-15 16:35:08 -07:00
Xudong Ma 72a0a38182 [okhttp] Make sure transportShutdown() always be called before calling transportTerminated(). 2015-10-12 16:34:55 -07:00
Carl Mastrangelo 6474938fe7 Allow non-host based authorities in OkHttp transport 2015-10-08 15:32:30 -07:00
Carl Mastrangelo d42a09b0e4 Add authority work around for OkHttp channels 2015-10-07 15:04:49 -07:00
Kun Zhang ff3dbf7b0a Deprecate OkHttpChannelBuilder#overrideHostForAuthority
It is a duplication of overrideAuthority().
2015-09-11 16:22:36 -07:00
Eric Anderson 538cf215f0 Add usePlaintext to ManagedChannelBuilder 2015-09-11 09:57:42 -07:00
Eric Anderson 5b2a03a02e Add overrideAuthority to ManagedChannelBuilder
We want to allow overriding authority in the ManagedChannelBuilder for
testing. In doing that, we basically require that all Channels support
authority. In reality, this simplifies things and is already being done
by the C implementation, as their unix domain socket support uses
"localhost" just like our in-process transport now does.

We can debate some whether "localhost" is really the most appropriate
authority for the in-process transport, but that should probably happen
later since "localhost" is "good enough" for now.
2015-09-11 09:37:49 -07:00
Eric Anderson de32e29592 Add overrideAuthority to OkHttpChannelBuilder 2015-09-11 09:37:48 -07:00
nmittler 0cd28dd32b Fixing okhttp hang when tls nego fails.
Negotiation failure results in a RuntimeException, which is not properly  handled by the okhttp code, resulting in the client hanging.

Refactored the code to shutdown the transport when TLS negotiation fails.
2015-09-10 11:51:14 -07:00
Eric Anderson df7bf44687 Enable license header checking in checkstyle 2015-09-10 11:29:00 -07:00
Eric Anderson 31394aa9df Let transports be channel service providers for generic usage
This provides an API for applications to use gRPC without using
ExperimentalApis. It also allows swapping out a transport implementation
in the future.
2015-09-09 11:06:35 -07:00
Xudong Ma bdaf7b3236 okhttp: Skip trash data for finished stream. 2015-09-03 23:44:43 -07:00
Louis Ryan 6a782a035e Use Executor in stable builder APIs instead of ExecutorService 2015-09-03 14:38:13 -07:00
Carl Mastrangelo 07a7279742 Daemonize OkHttp and Netty 2015-09-03 14:35:04 -07:00
nmittler b687bdc742 Refactoring channel API.
Client:
* New ManagedChannel abstract class.
* Adding ping to Channel.
* Moving builders and implementations to internal.

Server:
* Added lifecycle management API to Server (mirroring ManagedChannel).
* Moved ServerImpl, AbstractServerBuilder and handler registries to internal.
* New ServerBuilder abstract class (mirroring ManagedChannelBuilder).

Fixes #545
2015-09-03 11:22:29 -07:00
Eric Anderson 210114d4a2 Ease use of JWT by passing URI to auth library
The URI no longer needs to be provided to the Credential explicitly,
which prevents needing to know a magic string and allows using the same
Credential with multiple services.
2015-09-01 15:42:58 -07:00
nmittler d3ab427fca Enforce content-type on client and server.
Fixes #360
2015-09-01 06:59:46 -07:00
Xudong Ma a3f2f6249e OkHttp: Fix race condition between sendCancel and sendFrame 2015-08-27 15:11:23 -07:00
nmittler 15f02ba19c Adding maxMessageSize config option
Fixes #832
2015-08-26 15:32:33 -07:00
nmittler 777e928536 Removing transport shutdown hooks from channel builder
The current process of building a channel is a bit complicated in that transports have to provide a own shutdown hook to the channel builder in order to close shared executors. This somewhat entagled creation pattern makes it difficult to separate the process of channel building from transport building. Better separating these two should make the code more readable and maintainable moving forward.
2015-08-25 08:38:39 -07:00
Xudong Ma 485bc9c83c OkHttp: Make sure TransportListener.transportReady() can only be called once. 2015-08-24 13:39:37 -07:00
Carl Mastrangelo a508c1d4f5 Remove Headers 2015-08-24 11:41:10 -07:00
Xudong Ma 21f9b44d14 Use status UNAVAILABLE for IOException thrown by OkHttp reading path, which can also be triggered by HTTP/2 issues. 2015-08-21 16:42:22 -07:00
nmittler aeae7a8e74 Rename HttpUtil to GrpcUtil.
It's not really just for HTTP, it has becoming a dumping ground for many internal constants/utilities.
2015-08-21 14:02:26 -07:00
Xudong Ma d2ab1c26cb OkHttp: Call ClientTransport.Listener.transportReady() after receiving settings frame. 2015-08-19 16:20:22 -07:00
Eric Anderson 9d1b33cae3 Remove unused variables 2015-08-14 14:53:10 -07:00
Carl Mastrangelo 572f4332a7 Remove Trailers 2015-08-13 17:11:29 -07:00
Xudong Ma ca7587f641 Change some error status usages to be consistent with other gRPC implementations. 2015-08-13 13:14:21 -07:00
Xudong Ma a4c7d9a08a Redo b1e2aaebc0, with some changes to prevent test flaky. 2015-08-12 13:50:26 -07:00
Kun Zhang e1bd6ef45f Clean up the left-over of the transport package reorganization 2015-08-11 12:48:02 -07:00
Kun Zhang 9eed577d3d Revert "okHttp: Set max_concurrent_stream to 0 before the connection is connected."
This reverts commit b1e2aaebc0.
Broke tests.
2015-08-11 12:42:54 -07:00
Xudong Ma b1e2aaebc0 okHttp: Set max_concurrent_stream to 0 before the connection is connected.
So that the written messages will be queued inside the pending stream instead of the serializingExecutor.
2015-08-11 11:36:26 -07:00
Xudong Ma ddea7435c9 Remove stream id check for writing path, it breaks the starting of pending streams.
And fixes OkHttpClientTransport.mayHaveCreatedStream() for the case that streamId is Integer.MAX_VALUE - 2.
2015-08-11 09:36:42 -07:00
Xudong Ma b42122b035 Update test to demonstrate that pending streams will not be started if the transport is in goAway status. 2015-08-10 17:03:59 -07:00
Kun Zhang d2929cd1a3 Reorganize packages.
Reserve io.grpc for public API only, and all internal stuff in core to
io.grpc.internal, including the non-stable transport API.

Raise the netty/okhttp/inprocess subpackages one level up to io.grpc,
because they are public API and entry points for most users.

Details:

- Rename io.grpc.transport to io.grpc.internal;
- Move SharedResourceHolder and SerializingExecutor to io.grpc.internal
- Rename io.grpc.transport.{netty|okhttp|inprocess} to
  io.grpc.{netty|okhttp|inprocess}
2015-08-10 15:04:29 -07:00
Xudong Ma ba103fb871 OkHttp: make the pending stream cancellable. 2015-08-07 11:25:28 -07:00
Kun Zhang fc85a4085a Add more documentation for transports.
- Add package descriptions for transport, netty and okhttp.
- Describe transports (netty, okhttp and inprocess) in README
2015-08-06 17:24:42 -07:00
Carl Mastrangelo 67fc45d036 Rename Duplex to Bidi 2015-08-05 17:05:47 -07:00
Xudong Ma 7d1e65c111 Switch ALPN/NPN to advertise only h2 2015-08-05 11:25:05 -07:00
Xudong Ma c55657e3c5 Make new stream call asynchronous when the MAX_CONCURRENT_STREAMS is reached. 2015-08-03 11:38:18 -07:00
Carl Mastrangelo d2b1b37ed7 Add a transport ready for use with retry 2015-07-31 15:24:44 -07:00
Carl Mastrangelo bd8987af1a Add a status to Transport shutdown 2015-07-29 15:35:38 -07:00
Xudong Ma abfdbf69e5 OkHttp: sync error map with gRpc spec. 2015-07-29 08:29:31 -07:00
Xudong Ma dde1e809a7 Adjust @GuardedBy to pass internal GuardedBy Checking.
This is required by our internal sync.
2015-07-28 09:49:18 -07:00
Xudong Ma e36a64e6a6 Correctly handle unknown http2 error code. 2015-07-27 15:49:28 -07:00
Xudong Ma 750f6265e2 Simplify locking model of OkHttp Transport, avoid potential deadlock.
1. Remove the stream lock, use transport lock instead.
2. Protected streams map with the transport lock instead of using synchronized map.
2015-07-27 08:13:19 -07:00
Carl Mastrangelo 2eaeacafe8 Added basic unit test and reorg how onready calls are made
Forgot to add this last file

updated method name

Remove unused function

Remove helper function for threshold edge detection

Remove helper function for threshold edge detection

Re make listener abstract
2015-07-22 14:45:23 -07:00
Xudong Ma 5cc4e84e6e okhttp: Enable TLS by default. 2015-07-21 16:30:57 -07:00
Xudong Ma e8086b5351 Support NPN fallback for Android. 2015-07-21 16:26:15 -07:00
Xudong Ma f9f5b6af0a okhttp: make transport.start() async. 2015-07-21 10:13:02 -07:00
Xudong Ma ad7820ca9b Remove OkHttpClientTransport.DEFAULT_INITIAL_WINDOW_SIZE, use Utils.DEFAULT_WINDOW_SIZE instead. 2015-07-14 17:14:20 -07:00
Jack Coughlin 3e26b993ce Enforce request deadline
Use a ScheduledExecutorService in the ChannelImpl to terminate the
request by closing the ClientStream with status DEADLINE_EXCEEDED
2015-07-14 16:47:45 -07:00
Kun Zhang 73acc73dbf Remove Method and switch its users to MethodDescriptor.
Resolves #511.

- In generated code, make CONFIG private and METHOD_* fields public.
  METHOD_* fields are MethodDescriptors now, users of the CONFIG field
  should switch to using the METHOD_* fields.
- Move MethodType into MethodDescriptor (#529).
- Unify the fully qualified method name. It is fully qualified service
  name + slash + short method name. It doesn't have the leading slash.
- HandlerRegistry switches the key from short method name to fully
  qualified method name.
2015-07-09 09:29:03 -07:00
nmittler 8c1d38a0d8 Adding default User-Agent for netty and okhttp. 2015-07-08 15:56:54 -07:00
nmittler efbb65522b Simplifying flow control window config for Netty.
Fixes #494
2015-07-08 15:43:03 -07:00
Eric Anderson 30455fd2f4 Remove unused variables 2015-07-06 16:27:22 -07:00
Eric Anderson cb15779e59 Use class name, not instance, for invoking static method 2015-07-06 16:27:21 -07:00
Eric Anderson 10578e31c0 param in JavaDoc is lower-case 2015-07-06 16:27:21 -07:00
Xiao Hang 3777b8bf65 Use hostname instead of InetAddress for Socket creation.
On Android platform, the constructor using hostname will iterate through all solved ip address for making connection.
Before we implement happy eyeballs, this could be a workaround for Android users.
2015-06-29 19:12:15 -07:00
Eric Anderson 45da9c5766 Add a few ChannelImpl tests and improve error status 2015-06-26 12:19:41 -07:00
Xudong Ma 6e406ac4a5 Refactor OkHttpProtocolNegotiator, move Android related operations into an inner class. 2015-06-26 09:59:22 -07:00
Xudong Ma eb15eb2821 Some cleanup for okhttp:
1. Move DEFAULT_CONNECTION_SPEC to OkHttpChannelBuilder
2. make OkHttpClientTransport package-private
3. Rename OkHttpChannelBuilder.setConnectionSpec to connectionSpec
2015-06-18 13:29:18 -07:00
Xudong Ma 25da64937d Support setting ALPN for Android older than 5.0, OkHttp(2.3+) implementation only support such function for Android 5.0+.
Manually tested with the test App: https://github.com/madongfly/grpc-android-test.

Fixes #520
2015-06-11 14:39:26 -07:00
Josh Humphries 0d03f89467 add ping 2015-06-10 12:20:08 -04:00
Xudong Ma d242b225d0 Upgrade OkHttp to 2.4.
Fixes #490
2015-06-01 14:53:19 -07:00
Xudong Ma eed8f923af okhttp: Call onError for IOException thrown by FrameReader.nextFrame().
Since OkHttp wraps many protocol error as IOException, we need to send GoAway for such errors.

Fixes #487
2015-05-29 10:21:52 -07:00
Xudong Ma 0782c0408d Catch Exception thrown when query NPN selected protocol on a socket that haven't started hand shake. 2015-05-29 08:59:05 -07:00
Xudong Ma 2fe279f7c2 Add SelectedProtocolQuerier to get protocol selected by NPN on Android.
Fixes #467

Manually tested by using NPN on Android 4.3 (api level 18) talk to GFE.
2015-05-27 17:16:44 -07:00
Louis Ryan 641fc288fc Add support for indeterminate length messages. This will make using GRPC easier for non-proto payload types.
Sync to head
2015-05-26 15:44:46 -07:00
Xudong Ma 6affc8dcd5 upgrade okhttp to 2.3 2015-05-22 16:45:13 -07:00
Xudong Ma 0d480879e5 okhttp: outbound flow control.
Fixes #371
2015-05-21 23:05:54 -07:00
jonathanlin e50f671f1d Change OkHttpClientTransport#start to construct a Socket with the hostname and port if the address is unresolved. 2015-05-21 16:43:22 -07:00
Xudong Ma 7c1dabab5b okhttp: don't crash if receive window_update for an non-exit stream which may have existed.
This fixes #441
2015-05-19 10:27:03 -07:00
Xudong Ma 71447ce7af okhttp: changes for handling unknown stream id.
1. update connection window when receives DATA for existed streams.
2. kill the connection when receives unknown (not exist and never existed) stream id.
2015-05-18 14:15:42 -07:00
Xudong Ma c3125bebdb okhttp: send reset when client receives halfClose from server before sending halfClose.
So that the server side stream can be fully closed.

This fixed #300
2015-05-14 12:05:51 -07:00
Eric Anderson 1787106cc7 isReady() should return false until stream allocated
isReady() can provide pushback while the call is in progress, but it
can also provide the pushback necessary when the client creates more
streams than permitted by MAX_CONCURRENT_STREAMS.

As part of this commit, OkHttp is now calling onReady() after call
creation (it previously never called onReady()).
2015-05-12 16:41:50 -07:00
Xudong Ma 7ecb6fa431 okhttp: Catch Exceptions thrown by the frist platform.getSelectedProtocol(sslSocket), since in some implementations, querying selected protocol before the handshake will fail with exception. 2015-05-11 13:09:15 -07:00