Commit Graph

455 Commits

Author SHA1 Message Date
Jakob Buchgraber 0d6a9de54c netty: deduplicate javadoc accidentially introduced in e80b136495 2016-07-10 09:51:16 +02:00
Jakob Buchgraber e80b136495 Fix wrong use of checkNotNull in WriteQueue.
* Fix wrong use of checkNotNull in WriteQueue.

The issue was found and reported by @blakearnold. Thank you!
2016-07-08 16:00:34 +02:00
Eric Anderson 16b096b571 Reduce default max message size to 4 MiB
Fixes #1676
2016-07-07 13:34:53 -07:00
Jakob Buchgraber 2d7347fbfc netty: undo commit 6a55e29 as netty's DefaultThreadFactory has been fixed 2016-07-02 13:23:41 +02:00
Jakob Buchgraber 1257f96a00 netty: reduce allocations in write queue.
- Merge all the command objects with QueuedCommand so to save one object allocation per write.
- Add unit tests
2016-07-02 12:17:54 +02:00
Carl Mastrangelo 2292cbfca0 netty: prevent race between transportCreated and transportShutdown 2016-07-01 15:57:47 -07:00
Jakob Buchgraber c5733742ce netty: fix incorrect usage of AsciString.
An AsciiString object may only use a subsection of its backing byte array. We need to test for this and return a copy of the subsection if necessary.
Big thanks to @normanmaurer for uncovering this issue: https://github.com/netty/netty/issues/5472
2016-06-30 16:28:45 +02:00
ZHANG Dapeng 8ed2dc8bec testware: fix flakes caused by pickUnusedPort
Resolves #1756

The thread-unsafe method `io.grpc.testing.TestUtils.pickUnusedPort` causes flakes (#1756) in windows. Need to avoid use of this method in test as in windows the tests are running in different jvms and concurrent calls of this method in multiple processes tend to return the same port number.

There are some usages of this method in benchmarks, so moved the method to `io.grpc.benchmarks.Utils` and the method will only be used in benchmarks and not in test.
2016-06-28 13:34:38 -07:00
Jakob Buchgraber fc5197fbf4 netty: detect when ALPN was not used. Fixes #522 2016-06-25 15:59:30 +02:00
Kun Zhang 38b950f4f9 core: add transportInUse() to transport listener.
A transport is "in use" iff number of streams > 0. In following changes
the channel will use this information when deciding whether it should
transit to the IDLE mode (#1276).
2016-06-15 13:40:44 -07:00
Kun Zhang 432cec7973 core: CallCredentials
Introduce CallCredentials as a first-class option to allow applications
to set per-call credentials into headers for outgoing RPCs. This will
supersede ClientAuthInterceptor. It has access to more
information (e.g., transport attributes, MethodDescriptor) and allow
results to be returned asynchronously, e.g., from a blocking I/O, which
was problemantic with ClientAuthInterceptor.
2016-06-09 17:46:15 -07:00
ZHANG Dapeng b88ea27b53 core/internal: add 3-arg newStream method to ClientTransport interface (#1898)
adding 
ClientStream newStream(MethodDescriptor<?, ?> method, Metadata headers, CallOptions callOptions);
to ClientTransport interface

Created this PR first because both fail fast implementation and another change will be using this interface change
2016-06-06 19:43:15 -07:00
Eric Anderson c6fd94ca85 Implement shutdownNow
Fixes #448
2016-06-02 17:39:59 -07:00
Jakob Buchgraber c6c74799f4 netty: add toString() to GrpcHttp2Headers 2016-06-02 18:18:55 +02:00
Carl Mastrangelo 676bf4854f core: fix nags from linter 2016-06-01 13:58:07 -07:00
Carl Mastrangelo 02eb24b3bd core,netty,okhttp: move user agent removal closer to where it is set 2016-06-01 12:55:21 -07:00
Carl Mastrangelo fa22259e3a netty: use custom Http2Headers class for encoding Metadata
Before:
Benchmark                              (headerCount)    Mode     Cnt     Score    Error  Units
HeadersBenchmark.convertClientHeaders             10  sample  127008   631.214 ±  3.543  ns/op
HeadersBenchmark.convertClientHeaders             20  sample  142036  1125.874 ± 21.114  ns/op
HeadersBenchmark.convertClientHeaders             50  sample  117570  2678.635 ± 47.764  ns/op
HeadersBenchmark.convertClientHeaders            100  sample  115919  5427.720 ± 67.956  ns/op
HeadersBenchmark.convertServerHeaders             10  sample  133903   610.970 ±  3.094  ns/op
HeadersBenchmark.convertServerHeaders             20  sample  138155  1154.304 ±  4.595  ns/op
HeadersBenchmark.convertServerHeaders             50  sample  120078  2658.175 ± 38.679  ns/op
HeadersBenchmark.convertServerHeaders            100  sample  120509  5212.341 ± 49.062  ns/op

After:
Benchmark                              (headerCount)    Mode     Cnt     Score    Error  Units
HeadersBenchmark.convertClientHeaders             10  sample  102473   407.383 ±  2.693  ns/op
HeadersBenchmark.convertClientHeaders             20  sample  103205   791.241 ± 38.054  ns/op
HeadersBenchmark.convertClientHeaders             50  sample  173817  1840.311 ±  5.718  ns/op
HeadersBenchmark.convertClientHeaders            100  sample  169984  3690.753 ± 44.308  ns/op
HeadersBenchmark.convertServerHeaders             10  sample  103615   401.661 ±  2.922  ns/op
HeadersBenchmark.convertServerHeaders             20  sample   99060   823.453 ±  5.553  ns/op
HeadersBenchmark.convertServerHeaders             50  sample  171824  1846.788 ± 29.840  ns/op
HeadersBenchmark.convertServerHeaders            100  sample  171622  3670.354 ±  7.127  ns/op
2016-05-25 17:23:51 -07:00
Carl Mastrangelo 1cc76d8132 core,netty,okhttp: move user agent out of client call and into the transport 2016-05-25 15:11:42 -07:00
Carl Mastrangelo 5e30b2f7ba netty: speed up header conversion by caching user agent string
Performance gain seems to be about 100-200ns based on a a couple trials.

Benchmark                                 (headerCount)  (validate)    Mode     Cnt     Score    Error  Units
HeadersBenchmark.convertClientHeadersOld             10       false  sample  187490   858.234 ±  3.992  ns/op
HeadersBenchmark.convertClientHeadersOld             20       false  sample  113589  1407.557 ± 45.178  ns/op
HeadersBenchmark.convertClientHeadersOld             50       false  sample  100725  3141.936 ± 55.175  ns/op
HeadersBenchmark.convertClientHeadersOld            100       false  sample  109742  5707.748 ± 38.222  ns/op
HeadersBenchmark.convertHeaders                      10       false  sample  109137   748.486 ±  4.060  ns/op
HeadersBenchmark.convertHeaders                      20       false  sample  133639  1238.528 ± 51.914  ns/op
HeadersBenchmark.convertHeaders                      50       false  sample  107914  2915.602 ± 10.017  ns/op
HeadersBenchmark.convertHeaders                     100       false  sample  110305  5682.404 ± 44.032  ns/op
2016-05-23 17:49:30 -07:00
Eric Anderson 39d1e31547 netty: Fix test to support netty 4.1.0.Final 2016-05-23 13:22:18 -07:00
Eric Anderson 6382015f9d internal: Split-state AbstractStream; sending and receiving
This introduces an AbstractStream2 that is intended to replace the
current AbstractStream. Only server-side is implemented in this commit
which is why AbstractStream remains. This is mostly a reorganization of
AbstractStream and children, but minor internal behavioral changes were
required which makes it appear more like a reimplementation.

A strong focus was on splitting state that is maintained on the
application's thread (with Stream) and state that is maintained by the
transport (and used for StreamListener). By splitting the state it makes
it much easier to verify thread-safety and to reason about interactions.

I consider this a stepping stone for making even more changes to
simplify the Stream implementations and do not think some of the changes
are yet at their logical conclusion. Some of the changes may also
immediately be replaced with something better. The focus was to improve
readability and comprehesibility to more easily make more interesting
changes.

The only thing really removed is some state checking during sending
which is already occurring in ServerCallImpl.
2016-05-23 12:33:49 -07:00
Carl Mastrangelo 8090effa2d netty: don't revalidate when converting between Metadata and Http2Headers 2016-05-23 11:02:22 -07:00
Eric Anderson 27dffdfe03 netty: call transportShutdown immediately on ID exhaustion
Fixes #1819
2016-05-13 13:39:47 -07:00
Kun Zhang 95973827f5 Refactor HandlerRegistry.
See #933

- Create InternalHandlerRegistry, an immutable look-up table. Handlers
  passed to ServerBuilder.addService() go to this registry. This covers
  the most common use cases. By keeping the registry internal we could
  freely change the registry's interface to accommodate optimizations,
  e.g., for hpack.

- The internal registry uses a flat fullMethodName -> handler look-up
  table instead of a hierarchical one used before. It faster because it
  saves one look-up and a substring.

- Introduces the fallback registry, settable by
  ServerBuilder.fallbackHandlerRegistry(), for advanced users who want a
  dynamic registry. Moved the current MutableHandlerRegistryImpl to
  io.grpc.util.MutableHandlerRegistry as a stock implementation of the
  fallback registry. The io.grpc.MutableHandlerRegistry interface is now
  removed.
2016-05-04 17:12:32 -07:00
Carl Mastrangelo bc661e7fbb all: Finish adding tracking issues for ExperimentalApi 2016-05-03 16:15:57 -07:00
Carl Mastrangelo c6faf3541b Add a log message for unknown client streams 2016-05-02 14:04:19 -07:00
ZHANG Dapeng aed886d8de use Jetty ALPN agent instead of Jetty ALPN
#1497
2016-05-02 14:01:36 -07:00
Eric Anderson 80baa631a7 Use return value of Status.augmentDescription 2016-05-01 08:11:45 -07:00
ZHANG Dapeng 804991e80d validate sslContext in Netty channel/server builder #1699 (#1724)
validate sslContext in Netty channel/server builder #1699

resolves #1699
2016-04-27 13:02:43 -07:00
Carl Mastrangelo 38a91f83e1 Fix lint warnings found on internal import 2016-04-26 13:21:25 -07:00
Carl Mastrangelo 00f8f349b2 Don't allocate extra byte for each MessageFramer 2016-04-21 10:48:53 -07:00
Carl Mastrangelo d0d946ec9f new name 2016-04-18 16:21:53 -07:00
Carl Mastrangelo c4e8b1f10f Rename internal.Server to internal.TransportServer 2016-04-18 15:50:20 -07:00
Eric Anderson 6ab27aba13 Update checkstyle version and sync style updates 2016-04-18 09:15:25 -07:00
Carl Mastrangelo 51fd870cfd Add getting the port out of a Server 2016-04-13 13:54:45 -07:00
nmittler 22e719a5f9 Convert Netty IOExceptions to UNAVAILABLE.
Also inspecting the entire causal chain to identify the best possible Status.

Fixes #1053
Fixes #1522
2016-04-13 11:47:58 -07:00
Carl Mastrangelo 0ed059a408 Add rst error detail in OkHttp 2016-04-08 13:19:14 -07:00
Carl Mastrangelo 7d889b6911 Reuse metadata array when making http2 headers, and reduce some array copies 2016-04-08 13:08:07 -07:00
Kun Zhang 6a55e2990b Force thread group on threads created by Netty's DefaultThreadFactory.
As a workaround for https://github.com/netty/netty/issues/5084
2016-04-06 14:30:21 -07:00
Eric Anderson 2a5a41b600 Fix UNAVAILABLE codes missing descriptions
All status codes we generate from the library should have more
information available, either in the description or as a cause.
2016-03-31 09:51:33 -07:00
Kun Zhang 49b462784f Raise visibility of NettyTransportFactory to protected.
It's needed by internal code.
2016-03-29 12:06:18 -07:00
Carl Mastrangelo 65d3847d14 Remove references to Throwable.propagate 2016-03-22 15:47:52 -07:00
Lukasz Strzalkowski c3011b0798 Move server call keys to ServerCall class 2016-03-17 19:46:26 -04:00
buchgr d927180a63 Use Netty's DefaultThreadFactory instead of Guava's ThreadFactoryBuilder.
So far, we have passed a custom Executor to the NioEventLoopGroup constructor,
in order to get custom thread names and be compatible with both Netty 4 and
Netty 5. However, Netty 5 is no more (RIP) and Netty's DefaultThreadFactory
includes some optimizations around thread local storage, that Guava's executor
does not have.

The thread names will be a bit different, as DefaultThreadExecutor additionally
puts in the thread pool id after the name prefix.

For example:

Before:
grpc-default-boss-ELG-0
grpc-default-worker-ELG-0
grpc-default-worker-ELG-1

After:
grpc-default-boss-ELG-0-0
grpc-default-worker-ELG-1-0
grpc-default-worker-ELG-1-1
2016-03-17 00:43:26 +01:00
buchgr 3c68c053f7 Remove ReferenceCounted and add close() to ClientTransportFactory. Fixes #927 2016-03-17 00:31:04 +01:00
Lukasz Strzalkowski 6a67a97a73 Add attributes to ServerCall 2016-03-16 15:39:42 -07:00
Kun Zhang b9c12327eb Add log ID.
To ManagedChannelImpl, TransportSet and all client transport
implementations, so they can be correlated in the logs. Also added more
life-cycle logging in general.
2016-03-09 13:52:32 -08:00
Eric Anderson d192f1a6cb netty: GOAWAY should trigger transportShutdown
Long-lived streams or lengthy RPCs can keep the transport open for
minutes after a GOAWAY is received. Previously, during this time any new
RPCs would fail with a message like:

> Cannot create stream 5 since this endpoint has received a GOAWAY frame
> with last stream id 3

All usages of goAwayStatus were replaced with lifecycleManager. Although
note that previously goAwayStatus() would never return null because it
would generate a Status if the current field was null.
getShutdownStatus() does not have this feature, so some code was
rearranged to guarantee the Status is non-null before retrieving it.

The listener handling was simplified by 1) avoiding the need for
thread-safety and 2) moving state keeping into a small class for easy
comprehensibility and simplified usage in tests.

NettyClientTransport.shutdown() no longer calls transportShutdown()
because it lies (because the message can be delayed for quite some time)
and because it was the only usage of lifecycleManager not on the event
loop.

Fixes #1359
2016-03-07 09:35:18 -08:00
Eric Anderson 3528467612 Treat ClosedChannelException as UNAVAILABLE to squelch test failures
Our tests are detecting cases where we are still getting
ClosedChannelException. We need to fix that because it is a useless
status, but until it is fixed we want a stable CI.

Fixes #1513 and NettyTransportTest.serverNotListening failures
2016-03-03 14:18:34 -08:00
Eric Anderson 1170afd168 Add transport test for Netty
Netty client shutdown would race with the negotiation handling and
circumvent AbstractBufferingHandler. Use a new command in order to
leave channel.close() available for abrupt killing of the connection
when connecting.

ping_afterTermination was previously racey that made it succeed. After
fixing the test, Netty would consistently fail to call callback. After
fixing Netty to fail the callback it was not using the right status
because when Netty's channel is closed none of our handlers are run.
This reliably fails the future with ClosedChannelException, which is
useless, so now we special-case that exception and fill in the reason
for shutdown.

To prevent accidentally reporting Status.OK, the transports no longer
use OK when calling transportShutdown. The OK status was already no
longer being consumed, since keying off whether transportReady was
called is more helpful.

This fixes #1330
2016-03-01 17:43:30 -08:00
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
Carl Mastrangelo 74088c4fb4 Allow authority override to be propagated to Protocol Negotiators 2015-10-22 15:27:07 -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
nmittler 6e04c3100e Adding consistent exception handling for Netty
NettyClientHandler currently handles non-HTTP/2 exceptions properly by forcing a shutdown of the connection.  We need to do the server-side as well.

Fixes #1097
2015-10-05 11:46:50 -07:00
Carl Mastrangelo 2d067edf85 Allow host authority override. 2015-10-02 11:00:43 -07:00
Carl Mastrangelo 70cdf76212 adjust other usages in protocol negotiators 2015-09-29 10:57:23 -07:00
Carl Mastrangelo 75e291f062 docs 2015-09-29 10:48:24 -07:00
Carl Mastrangelo cb317c736c Update to share versions 2015-09-29 10:42:12 -07:00
Carl Mastrangelo ff19d90bb8 Force http2 connection when using tls 2015-09-29 10:38:26 -07:00
Carl Mastrangelo 46c18ea237 Move decompressor setting down into the AbstractStream 2015-09-28 10:25:58 -07:00
Xudong Ma f15f672b79 Correct the order of arguments. 2015-09-25 17:36:06 -07:00
nmittler f0d95798f8 Updating Netty to send a single SETTINGS frame.
Fixes #1059
2015-09-24 10:42:57 -07:00
Carl Mastrangelo 70fbd6735a Remove unused function in netty test 2015-09-23 15:15:31 -07:00
Carl Mastrangelo bfd74506fe Remove Netty test that fails with upstream 2015-09-23 13:47:33 -07:00
Eric Anderson 1e1d53b78f Fix test checking for invalid content type
Previously, if the content type was being ignored the error code would
have been UNKNOWN since there was no grpc-status. That seems very to
accidentally pass, so now if the content type is ignored it would get
OK.
2015-09-16 10:00:08 -07:00
Eric Anderson 1cfba96d17 Enforce sending headers before messages on server
ServerCall already had "headers must be sent before any messages, which
must be sent before closing," but the implementation did not enforce it
and our async server handler didn't obey.

The benefit of forcing sending headers first is that it removes the only
implicit call in our API and interceptors dealing just with metadata
don't need to override sendMessage. The implicit behavior was bug-prone
since it wasn't obvious you were forgetting that headers may not be
sent.
2015-09-11 17:39:40 -07:00
Carl Mastrangelo f6582d822d Add a hook to set TLS 2015-09-11 10:03:30 -07:00
Eric Anderson 538cf215f0 Add usePlaintext to ManagedChannelBuilder 2015-09-11 09:57:42 -07:00
Carl Mastrangelo 41d93cfd59 Use Providers in examples 2015-09-11 09:46:08 -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 3ae18eaef1 Add overrideAuthority to NettyChannelBuilder
Although the functionality is currently available by passing a
manually-created InetAddress, that requires that the user do I/O before
calling our API and does not work with naming in the future.
2015-09-11 09:37:43 -07:00
Carl Mastrangelo 416b745d8d Add a Server Provider 2015-09-10 12:23:17 -07:00
Eric Anderson df7bf44687 Enable license header checking in checkstyle 2015-09-10 11:29:00 -07:00
nmittler f80ca40fb9 Add client-side logging for TLS negotiation. 2015-09-09 13:16:24 -07:00
nmittler ccf328f367 Fixing erroneous server log when TLS nego fails
Only adding the server HTTP/2 handler after the TLS negotiation is successful.

Fixes #974
2015-09-09 11:42:41 -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
nmittler 9466eb5014 Adding tc_native to interop test scripts
Also adding better server error log
2015-09-09 07:16:49 -07:00
Carl Mastrangelo 3cf76326a2 Move decompressor setting to Server Impl 2015-09-08 13:03:27 -07:00
Eric Anderson 2a3ae36bd3 Only release event loops when unused
Resolves #926. Transports can still be alive when the Server shuts down,
but they are using the worker event loops. Only release the worker event
loops when all transport's channels are closed.
2015-09-03 18:29:34 -07:00
Carl Mastrangelo 07a7279742 Daemonize OkHttp and Netty 2015-09-03 14:35:04 -07:00
nmittler aefefb50c4 Supporting OpenSSL
- Upgrading to Netty 4.1.0.Beta6
- enabling OpenSSL in negotiation codepaths
2015-09-03 13:14:59 -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
Carl Mastrangelo 396f0606f3 Add test to prove RST closes stream, and remove hack from transport to force closure. 2015-08-31 13:26:49 -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
Carl Mastrangelo 345773504c Quick work around for Rst bug 2015-08-24 11:42:35 -07:00
Carl Mastrangelo a508c1d4f5 Remove Headers 2015-08-24 11:41:10 -07:00
Xudong Ma 13c14df055 Netty: Call ClientTransport.Listener.transportReady() after receiving SETTINGS frame. 2015-08-24 10:57:05 -07:00
nmittler e2f88fa904 Moving a few common utilities to GrpcUtil. 2015-08-24 07:53:32 -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
nmittler 9f7cb80108 Adding handling for stream exhaustion in Netty. 2015-08-21 13:01:17 -07:00
Kun Zhang 042b278256 Remove the first MethodDescriptor constructor.
that takes the service name and method name separately.

Also fix tests that are still using the old full qualified method name
format.
2015-08-20 14:19:50 -07:00
Kun Zhang 687a6f4814 Skip io.grpc.internal in javadoc.
Also move ExperimentalApi and Internal to io.grpc, so that they appear
in javadoc.
2015-08-20 08:48:44 -07:00
Xudong Ma bfcebeaa6a Netty: Use status INTERNAL instead of UNKNOWN for underlying Http2Exception. 2015-08-19 12:53:36 -07:00
Carl Mastrangelo 77b00e050b Add Part 1 of compression 2015-08-17 11:32:52 -07:00
Eric Anderson e72332ce5d Add missing Generic param to Answers 2015-08-14 14:53:11 -07:00
Eric Anderson 9d1b33cae3 Remove unused variables 2015-08-14 14:53:10 -07:00
nmittler 247ffb1377 Adding support for NPN fallback.
This takes some steps towards #525, but it won't be fixed until we
officially support OpenSSL. This is due to the fact that ALPN->NPN fallback
isn't supported with Jetty (since only one of the bootstrap plugins can be provided).
2015-08-14 11:21:14 -07:00
Carl Mastrangelo 572f4332a7 Remove Trailers 2015-08-13 17:11:29 -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 f681b5f8be Move Marshaller into MethodDescriptor 2015-08-11 10:53:38 -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
Eric Anderson be965b86ab Remove extraneous shutdown condition in NettyClientTransport
We didn't do the extraneous check in notifyTerminated()...
2015-08-10 13:40:45 -07:00
Eric Anderson 6236968d4b netty: Provide useful information if connect fails
Previously you would get an error saying, "Transport failed during
protocol negotiation" and no further information.
2015-08-10 13:24:04 -07:00
Eric Anderson 2addeae2db NettyClientHandler should handle all exceptionCaught()s
If NettyClientHandler doesn't then the exception will propagate to the
end of the pipeline, get logged, and cause any open calls to hang.
2015-08-10 13:24:03 -07:00
Eric Anderson 849ed1b995 netty: Simplify ping cancellation
ChannelInactive should be called in all cases of channel going down, so
we only need to cancel ping there. Use goAwayStatus for the error, since
we will be putting the most effort into making that status useful.
2015-08-10 13:24:00 -07:00
Eric Anderson 017cdd2ae9 netty: Remove connectionError and just use goAwayStatus
When connectionError was set, goAwayStatus was also set, so we shouldn't
lose any errors.

NettyClientTransport doesn't really need a Throwable, it just needs a
Status. Passing a Status out of NettyClientHandler reduces the number of
places that need to do transport-specific translation of Throwables into
Status codes.
2015-08-10 13:23:27 -07:00
Eric Anderson e1c348c24a netty: Don't double-process ssl handshake failures
As described in SslHandler's documentation, handshakeFuture() and
SslHandshakeCompletionEvent are equivalent forms of learning of
handshake completion. Watching both causes double-logging and serves no
purpose.
2015-08-10 12:38:47 -07:00
Eric Anderson 8d38d03c2f netty: If negotiation fails, continue failing new writes
Otherwise new writes will be written to the channel and will fail in
some unhelpful way.

Logging was removed as we really want to propagate the failure back to
the application via Calls, which is done by failing the
CreateStreamCommand message. Propagating back to the application via
call removes uncontrollable log spam and is necessary anyway to inform
the application what sort of failure occurred in order to appropriately
to react.
2015-08-10 12:38:46 -07:00
Jack Coughlin 3eaa92bea6 Send an RST_STREAM frame on server deadline 2015-08-10 09:51:54 -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 aebb58b200 Change awaitTerminated to awaitTermination 2015-08-06 13:52:17 -07:00
Xudong Ma 7d1e65c111 Switch ALPN/NPN to advertise only h2 2015-08-05 11:25:05 -07:00
Eric Anderson 41d875c7e3 Notify transportReady() in Netty 2015-08-03 16:50:05 -07:00
Eric Anderson 248f575a59 Make any lib-generated UNKNOWN have description
Note that even more importantly, this translates a RST_STREAM error code
to a gRPC status code. This is generally useful, but also necessary for
DEADLINE_EXCEEDED to be more reliable in 0eae0d9.

Fixes #687
2015-08-03 11:15:02 -07:00
Carl Mastrangelo bd8987af1a Add a status to Transport shutdown 2015-07-29 15:35:38 -07:00
Eric Anderson 26d77ecd2e Minor readability changes
Improved some consistency. writeHeaders was the only non-final
implementation method of ServerStream, even though it is really no
different than the others.
2015-07-23 10:57:00 -07:00
Carl Mastrangelo 0003e44886 Add simple server timeout support
Reintroduce throws

Add timeoutExecutor shutdown

Use a default future

Move timeout cancellation

Cancel the timeout in error cases
2015-07-15 09:33:16 -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 a6c51e7e14 Fixing some compiler warnings. 2015-07-08 16:10:54 -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
Kun Zhang d3c5b00827 Add CallOptions.
- Pass CallOptions to Channel.newCall() and
  ClientInterceptor.interceptCall().
- Remove timeout from AbstractStub.StubConfigBuilder and add deadline,
  which is stored in a CallOptions inside the stub.
- Deadline is in nanoseconds in the clock defined by System.nanoTime().
  It is converted to timeout before transmitting on the wire. Fail the
  call with DEADLINE_EXCEEDED if it's already expired.
2015-07-07 14:28:38 -07:00
Eric Anderson c7403127ea Revert swapping to the "canonical HTTP mapping"
The mapping is poorly suited for gRPC. C and Go don't even do any
mapping. We can improve the mapping in the future, but it is very
important that users don't start depending on the current mapping.

This change is "inspired by" the original code, but is even more
conservative.

Fixes #477
2015-06-25 12:15:34 -07:00
nmittler ae2b5bfda7 Exposing AbstractBufferingHandler so it can be used by custom protocol negotiators. 2015-06-24 13:59:33 -07:00
Jack Coughlin 77878a04ee Pass timeout header in ChannelImpl 2015-06-17 16:03:13 -07:00
nmittler 4322a43824 Throw error for Netty when Jetty ALPN not configured. 2015-06-17 14:19:55 -07:00
nmittler 9a6ded523a Cleanup of NettyClientTransportTest. 2015-06-16 13:11:03 -07:00
Eric Anderson 424c7e64c3 Avoid GCM in unit tests
GCM is very slow, and doesn't provide any benefit in unit tests. Even if
we were using tcnative and GCM is fast, using more available ciphers in
tests still makes sense. With this change building with Java 7 works
again, although that isn't the reason for the change.

On my machine with parallel building, it cuts full build time from
92 seconds to 39 seconds. For an incremental build after only changing
an interop test, the build time is cut from 73 seconds to 15 seconds.
2015-06-16 12:36:57 -07:00
nmittler cb486e461d Testing that buffered streams clean up properly upon disconnect. 2015-06-15 13:10:21 -07:00
nmittler 491aad2659 Changing Netty handlers to properly set initialSettings. 2015-06-11 15:06:20 -07:00
Josh Humphries 0d03f89467 add ping 2015-06-10 12:20:08 -04:00
nmittler 4ee2a6584a Allowing Netty TLS bootstrap handler to be sharable.
Fixes #504
2015-06-03 09:42:08 -07:00
Xudong Ma ffcc5f29c0 Remove unused imports.
to make CheckStyle happy.
2015-05-28 16:10:20 -07:00
nmittler 59f6f45cc4 Switching to Netty's ALPN support.
Also adding documentation for using gRPC with TLS-ALPN within Jetty.

Fixes #180
2015-05-28 13:04:10 -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
nmittler 65769c26b3 Making client-side negotiation more pluggable. 2015-05-20 14:37:16 -07:00
Eric Anderson 98c6355079 Disable Netty eventloop graceful termination
When shutting down the Netty event loop, we have already guaranteed that
all users of it are no longer running. Doing a shutdownGracefully is
just delaying graceful JVM termination by two seconds. This is very
noticeable for short-lived processes, like our integration tests.

We would actually also prefer to shutdown quickly and get a
RejectedExecutionException for any newly queued tasks, because that
would be a legitimate bug.

shutdown() is deprecated, thus we do shutdownGracefully with a timeout
of 0.
2015-05-15 18:19:57 -07:00
Louis Ryan d54911713a Implement writes to the channel using a dedicated write queue which allows for efficient flush
coalescing
2015-05-15 09:20:13 -07:00
nmittler 8f537e3ec6 updates to test native epoll 2015-05-14 15:33:55 -07:00
nmittler 5efbb6fe73 Allow 100 streams initially rather than 10.
The HTTP/2 spec suggests 100 as the recommended minimum for SETTINGS_MAX_CONCURRENT_STREAMS (https://tools.ietf.org/html/draft-ietf-httpbis-http2-17#section-6.5.2).  We should use this value as our default.
2015-05-13 14:22:46 -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
nmittler c3fa600eae Fixing compiler warning. 2015-05-12 16:23:39 -07:00
nmittler d5727c7fcd Deferring stream creation until receiving SETTINGS from server.
Additionally:
- Fixed bug where the decoder was given the incorrect encoder.
- Adding proper logging class for client/server.
2015-05-12 15:46:32 -07:00
nmittler b6407c4a10 Only complete graceful shutdown after buffered streams complete.
Upgrading to to the latest Netty as well.
2015-05-07 08:36:22 -07:00
nmittler b5443833d9 Fixing build issue. 2015-05-07 07:50:33 -07:00
nmittler d8d8ebd783 Adding logging to NettyClientHandler. 2015-05-06 14:38:22 -07:00