Commit Graph

463 Commits

Author SHA1 Message Date
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
Eric Anderson 35cb22dd42 Add comment to satisfy checkstyle 2015-05-05 08:47:00 -07:00
nmittler 64176d5560 Adding outbound flow control for Netty. 2015-05-04 12:19:57 -07:00
nmittler 7779b4fddf Cleaning up some warnings. 2015-04-30 13:57:38 -07:00
Xudong Ma 69c67042a6 De-flake OkHttpClientTransportTest.pendingStreamFailedByIdExhausted.
Fixes #356
2015-04-29 16:25:22 -07:00
Eric Anderson 9ffc71136e Fix style violations introduced in b2a3f7
The long line is caught by checkstyle so causes Travis-CI to fail.
2015-04-29 08:49:28 -07:00
Xudong Ma b2a3f7bd1e okhttp: respect SETTINGS_INITIAL_WINDOW_SIZE in outbound flow control. 2015-04-28 15:31:29 -07:00
Xudong Ma 8a5d927a9a Fix the race between failing and starting pending streams.
Fixes #330
2015-04-28 13:32:46 -07:00
Louis Ryan f679edcfcc Fix memeory leak in MessageFramer caused by allocation of 'empty' buffers never being released.
The buffers are not empty in reality as the allocators enforce a minimum size
2015-04-28 10:10:00 -07:00
Xudong Ma d0aad72441 okhttp: Clean up stream when error happens.
Resolves #279
2015-04-27 14:07:43 -07:00
Xudong Ma 4b00476d33 okhttp: Flushes headers out immediately, so that the server can be aware of the stream before receiving real data (or half close).
Resolves #257.
2015-04-27 13:10:04 -07:00
Xudong Ma 2f4aa5a490 Use Status "UNKNOWN" instead of "INTERNAL" when Status.fromThrowable can not find a cause with a status. 2015-04-24 10:52:27 +08:00
Louis Ryan f7010f2eac Use message size as a hint to the allocator for buffer capacity.
Set upper and lower bounds for Netty & OkHttp allocators based on transport limitations and benchmark results.
Fix OkHttp OutboundFlowController to chunk payloads larger than frameWriter.maxDataLength
Allow OkHttp to allocate buffers to FrameWriter larger than max DATA length
2015-04-23 16:58:43 -07:00
Eric Anderson fc3e41674b Propagate explicit flushes through MessageFramer
MessageFramer allows queing of data and explicit flushing. Sinks
generally can benefit from knowing when they are required to flush, so
we now tell them when MessageFramer received a flush so they only have
to flush when required.
2015-04-21 10:29:08 -07:00
nmittler f920badc5e Upgrading to the latest Netty version. 2015-04-16 08:42:56 -07:00
Xudong Ma 883eb62de4 OkHttp: Temporally support multiple h2-xx protocol on client side.
Since the user provided SSLSocketFactory (especially in Android) may already do the handshake when creates the SSLSocket, and it may choose a different protocol name other than the one OkHttp is using.

Resolves #293
2015-04-16 09:04:19 +08:00
Xudong Ma 775829a1b2 okhttp: Reset stream when receiving window is negative.
Resolves #215
2015-04-09 09:07:59 +08:00
Xudong Ma c2f039411a TLS support for okhttp transport.
Resolves #22

Add an API to let users specify ConnectionSpec.
2015-04-08 12:41:35 +08:00
Xudong Ma fcf1517054 Respect MAX_CONCURRENT_STREAMS in OkHttp client.
If a newStream is called  while MAX_CONCURRENT_STREAMS is reached, then get the call blocked and the request queued, until:
1. a running stream closed, and this newStream() request is accepted.
2. receives go-away from server, fail all pending new stream requests.
3. the available ids are exhausted.
2015-04-07 09:53:47 +08:00
Xudong Ma 9aae6f65fa checkstyle change:
1. Adds <property name="separateLineBetweenGroups" value="true"/> to CustomImportOrder to enfore blank line between imports groups.
2. Uses checkstyle 6.5, which fixed a bug of "CustomImportOrder checks import sorting according to ASCII order instead of case-insensitive alphabetical order".
2015-04-07 08:27:48 +08:00
Xudong Ma eb2d65bb0c Disable Nagle's algorithm, this was exposed by our internal micro benchmark, the streamingInputCall() method happened to have the write-write-read pattern which added 40ms extra delay.
According to our micro benchmark, this change improves the performance, see https://screenshot.googleplex.com/cfxjPGxkgF.png for the previous results, there were 4 out of 6 scenarios had higher latency than netty transport.

https://screenshot.googleplex.com/Rq92tYMvBE.png shows the results after this change, the latencies in all scenarios are less than netty transport.

This commit fixes #60.
2015-04-02 13:44:47 +08:00
Thomas ten Cate 9175d9d79e Fix data corruption issue receiving payloads > 2kB
Also add OkHttpReadableBuffer unit test, and increase the test string
length to expose the bug.

Also use array equality assertions in the base test, instead of
comparisons whose return value is discarded.

Fixes #231.
2015-03-22 13:14:57 +01:00
Eric Anderson 7865b031e1 okhttp: code style fix; handle exception
For code style, we either need a comment describing why an exception is
ignored or to actually handle the exception. In this case there doesn't
seem to be a strong reason to ignore the exception, but it isn't all
that important either, so just log at INFO.
2015-03-21 09:12:30 -07:00
Xudong Ma 79ef04bc91 Fix a race condition in the test, we may nitify MockFrameReader to return before it satrts waiting.
This commit fixes #223
2015-03-21 23:01:06 +08:00
Xudong Ma 7c6b627170 Close frame reader and notify the listener in reader thread, to avoid reading after reader is closed. 2015-03-17 08:04:07 +08:00
nmittler 23972a25b9 Adding outbound flow control API for the transport API 2015-03-16 14:17:03 -07:00
Eric Anderson c3e8dae6ce Add checkstyle checking
The checkstyle.xml is a slightly modified version of the upstream Google
checkstyle configuration. All changes have comment describing them.

Lots of warnings were corrected. Examples is the only project that has
warnings still, as the necessary changes require some thought.
2015-03-16 10:53:13 -07:00
Jakob Buchgraber 0076243063 Add WritableBuffer interface for zero copy data writes. Fixes #8
WritableBuffer is a generic interface that allows to transfer data
from gRPC directly to the native transport's buffer implementation.
2015-03-13 13:00:44 -07:00
nmittler fad21aafe7 Test receiving invalid stream IDs in okhttp
Fixes #173
2015-03-09 14:10:10 -07:00
Xiao Hang 62fb1d2c8a Bug fix. frameWriter and frameReader are not initialized when an Exception is thrown in socket creation.
So do not touch them in shutdown path if they are null.
2015-02-26 10:48:14 -08:00
Louis Ryan 95c6f5082c Udate TODOs to use Github user names 2015-02-23 12:46:28 -08:00
Jakob Buchgraber f2f120922d Fix race for stream id in OkHttpClientTransport.
When running benchmarks using the okhttp transport with lots of
streams per channel we would see the occasional GOAWAY frame with
the server logging exceptions of the like "io.netty.handler.codec.http2.Http2Exception: Request stream 575 is behind the next expected stream 583".

As quickly identified by @ejona86, there is a race between creating a new stream id and writing the header on the wire.
Putting both under the same lock ensures that those two always go together.

After this change the errors disappeared. The perf impact should be small as the actual write to
the socket doesn't happen within the lock, but only the scheduling of the write.
2015-02-19 21:29:31 -08:00
Eric Anderson 303482ad3c Fix race in OkHttp test
transportTerminated() is called after closing the streams, so we can't
just wait on the streams and expect it to have been called.
2015-02-13 08:54:50 -08:00
Eric Anderson 74f231a6dd Remove Guava Service from ClientTransport
OkHttp no longer cancels all calls on shutdown, as we want to allow
graceful shutdown. Such cancelling behavior will likely be provided by
Channel in the future.
2015-02-12 15:20:22 -08:00
Eric Anderson 8aa79b39fc Improve thread safety of newStream()
OkHttp should now have a thread-safe implementation of newStream.
Previously 'lock' was not held when checking goAway and the checking in
AbstractClientTransport was redundant.

Netty was thread-safe, but it was very hard to tell what guarantees were
necessary and what guarantees each piece was providing.
2015-02-06 14:12:01 -08:00
nmittler 89b8d7ff47 Moving decompression to the channel thread. 2015-01-29 14:55:40 -08:00
nmittler f83145865a Removing all references to "stubby" 2015-01-27 11:25:25 -08:00
Manik Surtani 0ca6584d19 Move to a non-snapshot version of OkHttp 2015-01-26 15:48:14 -08:00
Eric Anderson 0077e67274 Remove unused imports 2015-01-26 10:23:05 -08:00
nmittler 02cc5217a2 Fixing @GuardedBy annotation to use the correct lock name. 2015-01-22 12:33:24 -08:00
nmittler de3a13164f Changing gRPC Java inbound flow control model
The goal is to mirror the token-based approach used by the Reactive
Streams API.
2015-01-22 11:46:16 -08:00
ejona 4de2026492 Fix TODO attribution
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=84172357
2015-01-16 16:23:05 -08:00
simonma 3df1c33403 Reimplement test "readStatus" since v2 is here.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=84082247
2015-01-16 11:03:36 -08:00
ejona 7235a396b8 Remove Service API from ChannelImpl
This change loses asynchronous notification of channel state-change and
a way to wait until the channel is actually connected. Both of these are
expected to be added back as part of a health API. The important
distinction from Service is that ChannelImpl never permanently fails and
can revert from being started to connecting again.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=83875407
2015-01-15 13:42:49 -08:00
simonma 828f941e99 Remove dependency on guava Lists for initializing list.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=83808289
2015-01-15 13:42:43 -08:00
nathanmittler 11c363a7ae Disallowing message delivery after status has been delivered to the listener.
Summary of changes:

1) Merged the interfaces MessageDeframer2.Sink and DeframerListener into
MessageDeframer2.Listener. This simplifies the interface of
MessageDeframer2 quite a bit.

2) Added a deliveryPaused() handler to MessageDeframer2.Listener, which
is called by the deframer when there is not enough data to read/deliver
the next message.

3) Modified AbstractStream and AbstractClientStream to manage the timing
of when the closed() event is delivered to the listener. The
transportReportStatus ultimately controls this by creating a task to
close the listener. It either runs this task immediately or when the
next deliveryPaused() event occurs.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=83620903
2015-01-09 17:00:25 -08:00
ejona c0f41920bd Remove gRPC v1 support.
No major refactorings/simplifications were done. Only gRPC v1 support
infrastructure was removed.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=82737436
2015-01-08 14:43:23 -08:00
ejona 4523059762 Upgrade OkHttp for Android SNI / NPN fix
https://github.com/square/okhttp/pull/1137
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=82149209
2015-01-08 14:43:20 -08:00
ejona fc30031fd1 Change default gRPC protocol to v2.
Any place that force-sets the protocol to 2 or assumes the old value
is now removed. Unfortunately, it seems InProcessTransportTest has
some non-obvious dependency on gRPC v1.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=81597524
2015-01-08 14:43:18 -08:00
lryan 56e307fcb6 Add BSD license header to all source files
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=81447025
2015-01-08 14:43:17 -08:00
rocking 9dd0c944c8 Add SslSocketFactory support to OkHttpTransportFactory.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=81367843
2015-01-08 14:43:15 -08:00
zhangkun 2b116ef2cd Encode binary headers with Base64 on the wire, and requires all binary headers
have "-bin" suffix in their names.

Split Metadata.Marshaller into BinaryMarshaller and AsciiMarshaller.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=81306135
2015-01-08 14:43:15 -08:00
simonma 751a4df52a Remove JDK1.7 method InetSocketAddress#getHostString since JDK1.7 is only supported by Android after 4.4 KitKat.
Now we pass the host directly into OkHttpClientTranport for 2 reasons:
1. We don't need to call InetAddress/InetSocketAddress.getHostName(), which will do a reverse DNS lookup, may return a different value other than user specified.
2. In some tests, we want to change the host to match TLS cert, in such case, we can use OkHttpChannelBuilder.overrideHostForAuthority(String host) to override the host, then the transport will get the overridden value.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=81169377
2015-01-08 14:43:14 -08:00
zhangkun 8375cd00e8 GRPC Java clients will send the "te: trailers" header, and the server will
check for it, so that we can detect intermediate proxies that do not support
trailers.

-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=81084983
2015-01-08 14:43:13 -08:00
lryan c5e70c2310 Remove StreamState and use inboundPhase/outboundPhase instead
Remove synchronization on stateLock as we are not required to be thread safe
Add better toString for stream impls
Internal cleanup of various 'status' fields in AbstractClientStream
Remove 'stashTrailers' as we've already extracted status in layer above correctly

-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=80678356
2015-01-08 14:43:12 -08:00
nathanmittler 0d8477c85c Adding crude outbound flow control to OkHttp transport.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=80390743
2015-01-08 14:43:10 -08:00
nathanmittler 5d953e840b Updating gRPC code to use the latest Netty with application-level flow control support.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=80230204
2015-01-08 14:43:09 -08:00
lryan 669724a588 Rationalize the XXXStream classes to reduce code smear and make Netty/OkHTTP behave more consistently.
More cleanups to follow
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=79574504
2015-01-08 14:43:06 -08:00
zhangkun a71d887661 Make all transport factories package-private in favor of channel builders.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=79367593
2015-01-08 14:43:04 -08:00
ejona 9a5a8de65d [1/3] Move AbstractTransportTest to third_party.
This required making it no longer depend on GrpcClient. Instead, we now
use the builders that make using GrpcClient almost completely obsolete.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=78860648
2015-01-08 14:43:02 -08:00
nathanmittler 29cbef1f9b Renaming gRPC-java "newtransport" package to just "transport".
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=78596663
2015-01-08 14:43:00 -08:00