Commit Graph

886 Commits

Author SHA1 Message Date
Nick Ufer 9dd0c66929 netty: removes TODO in test for NettyServer 2021-08-05 11:27:27 -07:00
ZHANG Dapeng 860e97d12a
all: API refactoring in preparation to support retry stats (#8355)
Rebased PR #8343 into the first commit of this PR, then (the 2nd commit) reverted the part for metric recording of retry attempts. The PR as a whole is mechanical refactoring. No behavior change (except that some of the old code path when tracer is created is moved into the new method `streamCreated()`).

The API change is documented in go/grpc-stats-api-change-for-retry-java
2021-07-31 18:33:02 -07:00
Eric Anderson b2764595e6 netty: Refine workaround for Netty header processing for transparent retries
Nginx and C core don't do graceful GOAWAY and retries have matured such
that transparent retries may soon be on by default. Refining the
workaround thus can reduces error rate for users.

Fixes #8310
2021-07-30 16:42:21 -07:00
Eric Anderson a282019902
netty: Use charset=utf-8, not encoding=utf-8 for error pages
This has been wrong since the introduction of the code in df357cb8.
Noticed as part of https://github.com/grpc/grpc-go/pull/4491 . The error
text is generally ASCII, so this probably doesn't matter much.
2021-07-19 13:32:11 -07:00
ZHANG Dapeng 4f09073e0f
all: remove 2-arg ClientStreamListener.closed()
We used to have two ClientStreamListener.closed() methods. One is simply calling the other with default arg. This doubles debugging (e.g. #7921) and sometimes unit testing work. Deleting the 2-arg method to cleanup.

This PR is purely refactoring.
2021-06-29 10:27:03 -07:00
Eric Anderson 2258d2e3e9 netty-shaded: Use compile instead of runtime dep in pom for core
This is essentially re-adding #5901 after its behavior was "reverted"
in #8242. At the time grpc-core was the only dependency, so this change
only applies to grpc-core to make it a tiny bit easier to swap to
runtime scope in the future.
2021-06-18 07:48:04 -07:00
Daniel Zou dc74a31be1
Modify netty-shaded resources to reference shaded class names (#8258) 2021-06-16 07:56:48 -07:00
Eric Anderson 5642e01243
Replace failOnVersionConflict() with custom requireUpperBoundDeps
failOnVersionConflict has never been good for us. It is equivalent to
Maven dependencyConvergence which we discourage our users to use because
it is too tempermental and _creates_ version skew issues over time.
However, we had no real alternative for determining if our deps would be
misinterpeted by Maven.

failOnVersionConflict has been a constant drain and makes it really hard
to do seemingly-trivial upgrades. As evidenced by protobuf/build.gradle
in this change, it also caused _us_ to introduce a version downgrade.

This introduces our own custom requireUpperBoundDeps implementation so
that we can get back to simple dependency upgrades _and_ increase our
confidence in a consistent dependency tree.
2021-06-11 14:01:18 -07:00
Eric Anderson 8360e60330 netty/shaded: Leverage shadow plugin's publishing support
https://github.com/johnrengelman/shadow/pull/543 fixed project support,
which means the workaround is no longer necessary.
2021-06-11 08:32:11 -07:00
Eric Anderson d4c31ffad4 netty/shaded: Include deps automatically
Previously it required manually listing the direct deps of grpc-netty
which is error-prone as evidinced by the fact that we were missing
multiple deps (guava, perfmark-api). This didn't cause a problem because
grpc-core happens to bring in these same deps.
2021-06-08 12:27:12 -07:00
cfredri4 c8cd4cb260
netty: Support SocketAddress with ChannelCredentials (#8194)
This adds support for creating a Netty Channel with SocketAddress and ChannelCredentials.

This aligns with NettyServerBuilder.forAddress(SocketAddress address, ServerCredentials creds).
2021-05-24 09:49:20 -07:00
Chengyuan Zhang e5d0e9d9a8
api, core: support zero copy into protobuf (#8102)
Enables a codepath for zero-copy protobuf deserialization. Two new InputStream extension interfaces are added:

- HasByteBuffer: allows access to the underlying buffers containing inbound bytes directly without copying
- Detachable: allows customer marshaller to keep the buffers around until the application code is done with using the protobuf messages

Applications can implement a custom marshaller that takes over the ownership of ByteBuffers and wrap them into ByteStrings with protobuf's UnsafeByteOperations support. Then a RopeByteString, which is a in-place composite of ByteStrings can be created. This enables using the zero-copy codepath (requires immutable ByteBuffer indication) of CodedInputStream for deserialization.
2021-05-14 14:45:03 -07:00
Eric Anderson 1882c47eb9 netty: Remove Maven pom.properties from netty-shaded
The pom.properties are apparently present to allow tooling to know what
Maven artifact cooresponds to a JAR, just by looking at the JAR. Since
we shade Netty, that produces inaccurate results. This was noticed in
in #8077.
2021-05-11 15:36:44 -07:00
ZHANG Dapeng eb6764841b
netty: fix status message when GOAWAY at MAX_CONCURRENT_STREAMS limit
Resolves #8097
2021-04-16 16:10:38 -07:00
ZHANG Dapeng 49f9380fc9
netty: fix StreamBufferingEncoder GOAWAY bug
Fix a bug in StreamBufferingEncoder: when client receives GOWAY while there are pending streams due to MAX_CONCURRENT_STREAMS, we see the following error:
io.netty.handler.codec.http2.Http2Exception$StreamException: Maximum active streams violated for this endpoint.
2021-04-16 14:23:14 -07:00
Eric Anderson d8061c4ced netty: Add support for OpenJSSE
Tested with the interop client on Zulu 8 and Zulu 11 with
-XX:+UseOpenJSSE (after disabling tcnative). I was unable to add a new
case to TlsTest because adding OpenJSSE as a dependency in a Gradle
build fails: https://github.com/openjsse/openjsse/issues/19

Fixes #7907
2021-04-02 09:32:14 -07:00
Eric Anderson c26ee03cd9 netty: Add Http2Headers.setLong() for inbound headers
Starting in Netty 4.1.60, Netty will validate Content-Length headers
using getAll() and setLong(). While getAll() was documented as only used
in tests, it doesn't appear it was currently used in any tests.

While Http2NettyTest.contentLengthPermitted() was added to confirm that
Content-Length works, it won't actually exercise any interesting
behavior until we upgrade to Netty 4.1.60. However, I did test with
Netty 4.1.60 and it reproduced the failure in
https://github.com/grpc/grpc-java/issues/7953 and passed with this
change.

Since Netty is now observing/modifying the headers, it would seem
appropriate to implement a substantial portion of the Http2Headers API.
However, the surface is much larger than we'd want to implement for a
'quick fix' that could be backported. In addition, it seems much of the
API is just convenience methods, so it is probably appropriate to split
out a AbstractHeaders class from DefaultHeaders in Netty that doesn't
make any assumptions about the header storage mechanism.
2021-03-16 16:36:18 -07:00
yifeizhuang 528ef63c58
core: Move negotiationLogger from channel attributes to GrpcHttp2ConnectionHandler (#7933) 2021-03-10 16:43:56 -08:00
Eric Anderson 6fb84bc61c Call the HTTP/2 close() so that GOAWAY is issued 2021-02-22 22:45:24 -08:00
Eric Anderson f2eb0af550 netty: Allow handshakes to be interrupted by channel shutdown
If a handshake is ongoing during shutdown, this would substantially
reduce the time it takes to shut down. Previously, you would need to use
channel.shutdownNow() to have fast shutdown behavior, which is an
unnecessary use of the variant.

When the current approach was written WriteBufferingAndExceptionHandler
didn't exist and so it was hard to predict how the pipeline would react
to events (particularly because of HTTP/2 handler's re-definition of
close()). Now that WBAEH exists, this is more straight-forward.
2021-02-22 22:45:24 -08:00
Eric Anderson 0eab1c9176 netty: Consume mTLS and Trust/KeyManager Credentials API 2021-02-19 09:30:24 -08:00
Rui Liu 563288f0ad
netty: Log expected STREAM_CLOSED exceptions for already closed streams at FINE level
See this PR in netty: https://github.com/netty/netty/pull/9798 . It's
possible that one peer has closed the stream, yet another frame from
peers arrives after it. This is largely harmless, as explained in the PR
from netty repository. If we don't do this, the log will be polluted with
these harmless logs.

Example that would no longer be logged:

```
Jan 25, 2021 6:23:51 PM io.grpc.netty.NettyServerHandler onStreamError
WARNING: Stream Error
io.netty.handler.codec.http2.Http2Exception$StreamException: Received DATA frame for an unknown stream 27
        at io.netty.handler.codec.http2.Http2Exception.streamError(Http2Exception.java:147)
        at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder$FrameReadListener.shouldIgnoreHeadersOrDataFrame(DefaultHttp2ConnectionDecoder.java:596)
        at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder$FrameReadListener.onDataRead(DefaultHttp2ConnectionDecoder.java:239)
        ...
```
2021-02-02 12:21:55 -08:00
ZHANG Dapeng 45a151810c
all: implement Helper.createResolvingOobChannelBuilder(target, creds)
- Add APIs to `ClientTransportFactory`:
```java
public interface ClientTransportFactory {
  /**
   * Swaps to a new ChannelCredentials with all other settings unchanged. Returns null if the
   * ChannelCredentials is not supported by the current ClientTransportFactory settings.
   */
  SwapChannelCredentialsResult swapChannelCredentials(ChannelCredentials channelCreds);

  final class SwapChannelCredentialsResult {
    final ClientTransportFactory transportFactory;
    @Nullable final CallCredentials callCredentials;
  }
}
```

- Add `ChannelCredentials` to constructor args of `ManagedChannelImplBuilder`:
 ```java
public ManagedChannelImplBuilder(
      String target, @Nullable ChannelCredentials channelCreds, @Nullable CallCredentials callCreds, ...)
  ```
2021-01-28 09:49:53 -08:00
Chengyuan Zhang 32173975e0
Revert "netty: add exporting SSL/TLS master key log feature (#7724)" (#7792)
This reverts commit 9bc05fba67.
2021-01-08 15:45:58 -08:00
huangqiangxiong 9bc05fba67
netty: add exporting SSL/TLS master key log feature (#7724)
Enable this feature by setting the system property
   -Dio.netty.ssl.masterKeyHandler=true
or
   System.setProperty(SslMasterKeyHandler.SYSTEM_PROP_KEY, "true");
The keys will be written to the log named "io.netty.wireshark" in
the warnning level. To export the keys to a file, you can configure
log factory like: (with log4j.xml for example)
<appender name="key-file" class="org.apache.log4j.RollingFileAppender">
	<param name="file" value="d:/keyfile.txt"/>
	<layout class="org.apache.log4j.PatternLayout">
		<param name="ConversionPattern" value="%m%n"/>
	</layout>
</appender>
<category name="io.netty.wireshark">
	<priority value="DEBUG" />
	<appender-ref ref="key-file" />
</category>

Wireshark can analyze the messages gRPC over TLS with this
key log file.

close #7199
2021-01-08 13:11:24 -08:00
Yifei Zhuang 53da588dd1
Move multiple-port ServerImpl to NettyServer (#7674)
Change InternalServer to handle multiple addresses and implemented in NettyServer.
It makes ServerImpl to have a single transport server, and this single transport server (NettyServer) will bind to all listening addresses during bootstrap. (#7674)
2021-01-05 13:24:16 -08:00
Eric Anderson 8359d0b710
netty: Upgrade to Netty 4.1.52 and tcnative 2.0.34
The tiny cache size was removed from the bytebuf allocator and so was
deprecated. TLSv1.3 was enabled by the upgrade, which fails mTLS
connections at different times. Conscrypt is incompatible with the
default TrustManager when TLSv1.3 is enabled so we explicitly disable
TLSv1.3 when Conscrypt is used for the moment.
2020-12-29 15:20:46 -08:00
ZHANG Dapeng 90d61178a3
all: ChannelCredentials.withoutBearerTokens() and LoadBalancer.Helper API change (#7748)
API change (See go/grpc-rls-callcreds-to-server):

- Add `ChannelCredentials.withoutBearerTokens()`
- Add `createResolvingOobChannelBuilder(String, ChannelCredentials)`, `getChannelCredentials()` and `getUnsafeChannelCredentials()` for `LoadBalancer.Helper`

This PR does not include the implementation of `createResolvingOobChannelBuilder(String, ChannelCredentials)`.
2020-12-22 22:48:39 -08:00
Eric Anderson ec70b64610
Bump Gradle and plugin versions
Android plugins weren't touched, since they will need a lot more testing
when doing so.
2020-12-17 15:02:27 -08:00
Chengyuan Zhang 192614bf51
Revert "netty: create adaptive cumulator" (#7669)
This reverts commit 729175c783.
2020-11-25 14:37:48 -08:00
sanjaypujare 620d266677
xds: implement XdsServerCredentials (#7636)
Co-authored-by: Eric Anderson <ejona@google.com>
2020-11-18 12:46:29 -08:00
Sergii Tkachenko 729175c783
netty: create adaptive cumulator 2020-11-17 18:05:18 -05:00
Eric Anderson 172869e31e netty: Add plumbing for eagAttributes on server-side
This is to be used for xDS to inject configuration for the
XdsServerCredentials. We'd like a cleaner approach, but they mostly seem
to be more heavy-weight. We will probably address this at the same time
we handle the Executor being passed for TLS. In the mean time this is
easy, doesn't hurt much, and can easily be changed in the future.
2020-11-17 12:26:01 -08:00
Eric Anderson edcc6854a6 netty: Add ServerCredentials 2020-11-13 11:13:33 -08:00
James deBoer a589f520c1
netty: Improve an exception message with more context (#7593)
Adds the address we are attempting to bind to. This context is useful for tracking down errors in configuration.
2020-11-06 12:58:05 -08:00
Sergii Tkachenko d314c68126
Fix builders ABI backward compatibility broken in v1.33.0
* fix channel builders ABI backward compatibility broken in v1.33.0
* fix server builders ABI backward compatibility broken in v1.33.0
* makes ForwardingServerBuilder package-private
2020-10-29 12:06:37 -04:00
Eric Anderson 735b85fb33 netty: Differentiate GOAWAY closure status descriptions
With this, it will be clear if the RPC failed because the server didn't
use a double-GOAWAY or if it failed because of MAX_CONCURRENT_STREAMS or
if it was due to a local race. It also fixes the status code to be
UNAVAILABLE except for the RPCs included in the GOAWAY error (modulo the
Netty bug).

Fixes #5855
2020-10-29 09:04:37 -07:00
Eric Anderson 45b8b0eb60 netty: Abrupt GOAWAY should not cause INTERNAL status
The stream creation was failing because the stream id was disallowed:
Caused by: io.grpc.StatusRuntimeException: INTERNAL: http2 exception
	at io.grpc.Status.asRuntimeException(Status.java:533)
	at io.grpc.stub.ClientCalls$BlockingResponseStream.hasNext(ClientCalls.java:629)
	... 16 more
Caused by: io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2Exception$StreamException: Cannot create stream 222691 greater than Last-Stream-ID 222689 from GOAWAY.

The problem was introduced in 9ead606. Fixes #7357
2020-10-22 11:15:58 -05:00
sanjaypujare f9b428ab40
xds: implement XdsChannelCredentials (#7497) 2020-10-09 09:21:39 -07:00
Eric Anderson 1ffde15471 netty: Add ChannelCredentials 2020-10-07 13:58:37 -05:00
Eric Anderson c8a94d1059 api: Add ChannelCredentials 2020-10-07 13:58:37 -05:00
Eric Anderson cdeda50758 netty: Fix Javadoc for ShadingTest 2020-10-05 15:49:07 -05:00
Eric Anderson ec0d01d7a4 netty: TCP close during TLS handshake should be UNAVAILABLE
Normally the first exception/event experienced is the cause and is
followed by a stampede of ClosedChannelExceptions. In this case,
SslHandler is manufacturing a ClosedChannelException of its own and
propagating it _before_ the trigger event. This might be considered a
bug, but changing SslHandler's behavior would be very risky and almost
certainly break someone's code.

Fixes #7376
2020-10-01 15:12:53 -05:00
Eric Anderson 00e2d717a2 netty: BDP ping accounting should occur after flow control
It's hoped that this resolves the "too_many_pings" issue some users are
seeing that is worked around by GRPC_EXPERIMENTAL_AUTOFLOWCONTROL=false.
This change also avoids resetting the ping count for empty data frames
(which shouldn't really happen with gRPC).

The previous code failed to reset the ping count on HEADERS and
WINDOW_UPDATE. The code _appeared_ to have callbacks for WINDOW_UPDATE,
but was layered above the Http2Connection so was never called. Thus,
this version is much more aggressive then the previous version while
also addressing the correctness issue.
2020-09-28 17:23:12 -05:00
Eric Anderson 4c1bab9ed5 Prepare for JUnit 4.13
It deprecates ExpectedException and Assert.assertThat(T, org.hamcrest.Matcher).
Without Java 8 we don't want to migrate away from ExpectedException at
this time. We tend to prefer Truth over Hamcrest, so I swapped the one
instance of Assert.assertThat() to use Truth. With this change we get a
warning-less build with JUnit 4.13. We don't yet upgrade because we
still need to support JUnit 4.12 for some use-cases, but will be able to
upgrade to 4.13 soon when they upgrade.
2020-09-28 17:07:50 -05:00
Russell Shaw 5879b53c57
netty: Add support for IBMJSSE2 (#7422)
This is a very simple change to test for IBMJSSE2 security provider in addition to the others. IBM JRE does not support the Sun provider, but instead has IBMJSSE2 which supports the same API calls.

I tested this on Z/OS machine as now it works when before it couldn't find a security provider
2020-09-16 08:07:52 -07:00
ZHANG Dapeng ee5b5929d5
api,netty: Fix TruthIncompatibleType 2020-09-15 11:22:44 -07:00
Sergii Tkachenko d5dcfa737a
all: remove deprecated internal OverrideAuthorityChecker 2020-09-11 19:14:25 -04:00
Eric Anderson c919594962 netty-shaded: Fix publish regression for javadoc and sources
96ad6338 accidentally caused the javadoc and sources jars to no longer
be published for grpc-netty-shaded. It would appear to be due to the
jars being empty. This commit causes them to be published again.
2020-09-09 17:39:19 -05:00
Sergii Tkachenko b03f148ed9 core, netty: server builders extend a public API class 2020-09-03 16:26:04 -04:00
Sergii Tkachenko c29ad76dae Explain test value for flow control window 2020-09-02 14:51:39 -04:00
Sergii Tkachenko c056979671 netty: NettyChannelBuilder extends a public API class 2020-09-02 13:28:52 -04:00
ZHANG Dapeng 09367030ae
all: fix lint 2020-08-28 13:00:44 -07:00
Eric Anderson 0a99a20b70 netty: Provide an environment variable to toggle BDP monitoring
A user has reported a GOAWAY with too_many_pings when using BDP. We
aren't certain why it is happening, but want to provide a way to disable
BDP while we continue investigating. b/162162973
2020-08-07 17:34:09 -05:00
Eric Anderson e92b2275f9 Update to Error Prone 2.4
Most of the changes should be semi-clear why they were made. However, BadImport
may not be as obvious: https://errorprone.info/bugpattern/BadImport . That
impacted classes named Type, Entry, and Factory. Also
PublicContructorForAbstractClass:
https://errorprone.info/bugpattern/PublicConstructorForAbstractClass

The JdkObsolete issue is already resolved but is not yet in a release.
2020-08-06 10:56:16 -05:00
Eric Anderson 80d62bfce2 Upgrade to Mockito 3.3.3
verifyZeroInteractions has the same behavior as verifyNoMoreInteractions. It
was deprecated in Mockito 3.0.1 and replaced with verifyNoInteractions, which
does not change behavior depending on previous verify() calls. All instances
were replaced with verifyNoInteractions, except those in
ApplicationThreadDeframerTest which were replaced with verifyNoMoreInteractions
since there is a verify() call in `@Before`.
2020-08-06 10:49:23 -05:00
Eric Anderson 8400b17200 Bump Jetty ALPN to 2.0.10 for Java 8u252
Since Travis in on Java 8u252, we won't actually be testing Jetty ALPN at this
point. We're also not testing the Java 9 ALPN API on Java 8, since our current
version of Netty doesn't support it (but an upgrade is available that does).
2020-06-25 11:50:15 -05:00
Eric Anderson 295d927d8b core: Add migrating deframer
This provides a substantial ~3x performance increase to Netty async
streaming with small messages. It also increases OkHttp performance for
the same benchmark 40% and decreases unary latency by 3µs for Netty and
10µs for OkHttp.

We avoid calling listener after closure because the Executor used for
RPC callbacks may no longer be available. This issue was already
present in the ApplicationThreadDeframer, but full-stream compression is
not really deployed so was unnoticed.

DirectExecutor saw a 5-6µs latency increase via MigratingDeframer.
DirectExecutor usages should see no benefit from MigratingDeframer, so
disable it in that case.
2020-06-18 15:48:29 -05:00
Elliotte Rusty Harold 417d7700dd
deps: Update guava to 29.0 (#7079) 2020-06-03 13:48:02 -07:00
Reginald McDonald 408136301e
netty: return status code unavailable when netty channel has unresolved InetSocketAddress (#7023) 2020-05-21 16:15:53 -07:00
Nicholas Titcombe 3601190143
netty: use getOrCreate() for new instances of ChannelLogger AttributeKey. (#7048) 2020-05-21 12:43:35 -07:00
AgentK d89dd2db33
netty: log SocketExceptions at FINE, too
This PR changes the `NettyServerTransport#getLogLevel` method to log 
`SocketException`s to `LogLevel.FINE`, rather than exclusively pure
IOExceptions. This may fix an unintentional regression introduced in
c166ec2c, although the message in my java version (14.0.1) wouldn't have
passed the old logic for quieting either. This also fixes the issue
raised in #6423 that was locked for inactivity.

This fixes 
```
[2020/05/14 20:21:52   INFO] [io.grpc.netty.NettyServerTransport.connections] Transport failed
java.net.SocketException: Connection reset
        at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:345)
        at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:376)
        at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
        at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1125)
        at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:347)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:677)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:612)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:529)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:491)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:832)
```
being logged to level INFO, which occurs whenever a socket is improperly 
closed by the client, such as with the grpc-health-probe (They've got an
[open issue](https://github.com/grpc-ecosystem/grpc-health-probe/issues/34)
for this)
2020-05-15 15:31:35 -07:00
Jihun Cho 1c50bcafd5
netty: enable auto flow control tuning by default (#7015) 2020-05-11 16:38:58 -07:00
ZHANG Dapeng 0044f8ce56
all: migrate gradle build to java-library plugin
- Use gradle configuration `api` for dependencies that are part of grpc public api signatures.
- Replace deprecated gradle configurations `compile`, `testCompile`, `runtime` and `testRuntime`.
- With minimal change in dependencies: If we need dep X and Y to compile our code, and if X transitively depends on Y, then our build would still pass even if we only include X as `compile`/`implementation` dependency for our project. Ideally we should include both X and Y explicitly as `implementation` dependency for our project, but in this PR we don't add the missing Y if it is previously missing.
2020-05-04 16:44:30 -07:00
Jihun Cho 83a3b25e80
netty: allow to use bandwidth delay product (#6979) 2020-05-01 15:39:22 -07:00
Jihun Cho 0059c5ac04
netty: use netty default SO_BACKLOG (#6956) 2020-04-22 09:10:17 -07:00
Benedict Jin 9411e9716c
netty: support setting options of boss in NettyServer (#6947) 2020-04-21 10:20:20 -07:00
Kun Zhang 17b2b96d8a
netty: log the selection of allocators (#6930) 2020-04-15 14:44:02 -07:00
Eric Anderson 9ead606b84
netty: Reduce race window size between GOAWAY and new streams
The race between new streams and transport shutdown is #2562, but it is still
far from being generally solved. This reduces the race window of new streams
from (transport selection → stream created on network thread) to (transport
selection → stream enqueued on network thread). Since only a single thread now
needs to do work in the stream creation race window, the window should be
dramatically smaller.

This only reduces GOAWAY races when the server performs a graceful shutdown
(using two GOAWAYs), as that is the only non-racy way on-the-wire to shutdown a
connection in HTTP/2.
2020-04-10 12:03:23 -07:00
Eric Anderson 2c250ace52 netty: prevent interruption during bind from leaking channel
Fixes #6850
2020-03-27 17:21:22 -07:00
ZHANG Dapeng 5677a0b723
api,netty: fix MethodDescriptor and InternalKnownTransport for netty-shaded
Resolves #6765
2020-02-27 12:53:11 -08:00
ZhenLian 557da62305
netty: Upgrade Netty (4.1.45.Final) & tcnative (2.0.28.Final) 2020-02-06 10:03:14 -08:00
sanjaypujare 461d30adfb
netty: fix server and client handlers to check the correct alpn list (#6603) 2020-02-04 13:03:34 -08:00
Jihun Cho 2acca6ea3b
all: fix lint warnings (#6658) 2020-01-30 10:00:39 -08:00
Kun Zhang 74cde7e8b4
netty: add an internal option to disable native buffer (#6619)
This is needed for internal rollout where the native memory usage from netty makes task more prone to exceeding memory limits.
2020-01-21 11:37:02 -08:00
ZHANG Dapeng b8474d61c9
netty: fix a race for channelz at server transport creation
A race condition was reported by user in #6601:

`ServerImpl.start()` calls `NettyServer.start()` while holding `ServerImpl.lock`. `NettyServer.start()` awaits a submitted runnable in eventloop. However, this pending runnable may never be executed because the eventloop might be executing some other task, like `ServerListenerImpl.transportCreated()`, that is trying to acquire `ServerImpl.lock` causing a deadlock.

This PR resolves the particular issue reported in #6601 for server with a single port, but `NettyServer` (https://github.com/grpc/grpc-java/blob/v1.26.0/netty/src/main/java/io/grpc/netty/NettyServer.java#L251) and `ServerImpl` (https://github.com/grpc/grpc-java/blob/v1.26.0/core/src/main/java/io/grpc/internal/ServerImpl.java#L184) in general still have the same potential risk of deadlock, which need further fix.
2020-01-16 11:53:37 -08:00
Aleksei Kandybaev 18e099d9d3 netty: fix ENHANCE_YOUR_CALM debug data logging (#6596) 2020-01-13 14:59:23 -08:00
sanjaypujare dba09163de
netty: remove 'grpc-exp' from the list of next-protocol-versions in ALPN (#6592) 2020-01-09 16:41:20 -08:00
Eric Anderson c606519a5d bazel: Support maven_install
maven_install is strongly superior to previous forms of grabbing dependencies
from Maven as it computes the appropriate versions to use from the full
transitive dependencies of all libraries used by an application. It also has
much less boilerplate and includes dependencies with generated targets.

In the future we will drop the jvm_maven_import_external usages and require
maven_install, at which point we can swap to using the `@maven' repository and
no longer depend on compat_repositories.

Fixes #5359
2019-12-30 12:08:42 -08:00
ZhenLian 19805233ef netty: Add Executor When Creating SslContext
This PR is to add one more Executor parameter when creating the SslContext.
In Netty, we already have this implementation for passing Executor when creating SslContext: netty/netty#8847. This extra Executor is used to take some time-consuming tasks when doing SSL handshake. However, in current gRPC implementation, we are not using this API.

In this PR, the relevant changes are:

1. get the executorPool from ChannelBuilder or ServerBuilder

2. pass the executorPool all the way down to ClientTlsHandler

3. fill executorPool in when creating SslHandler
2019-12-30 08:33:16 -08:00
Kun Zhang 212da14200
netty: enable io.grpc.netty.useCustomAllocator by default (take 2) (#6528)
Since #6526 has resolved the memory leak, let's turn it back on.
2019-12-18 08:33:29 -08:00
Kun Zhang ada575dd24
netty: use singleton for the custom allocator. (#6526)
The allocator has a circular reference that prevents it from GC'ed,
thus causes memory leak if gRPC Channels are created and shutdown
(even cleanly) on a regular basis.

See https://github.com/netty/netty/issues/6891#issuecomment-457809308
and internal b/146074696.
2019-12-16 17:35:40 -08:00
Kun Zhang c032e2ebf9
Revert "netty: enable io.grpc.netty.useCustomAllocator by default (#6459)" (#6517)
This reverts commit b0e00fd4ba.

It may cause leak of netty native buffers when creating and shutting
down Channels on a regular basis.
2019-12-13 10:48:53 -08:00
Eric Anderson 9a646518cb
netty: NettyServer should close ProtocolNegotiator 2019-12-10 16:46:30 -08:00
Jihun Cho 1573e0d400
netty: log NativeIoException as FINE level (#6477)
resolves #6478
2019-12-03 13:05:04 -08:00
Kun Zhang b0e00fd4ba
netty: enable io.grpc.netty.useCustomAllocator by default (#6459) 2019-11-22 16:13:35 -08:00
ZHANG Dapeng 2d454d478c
Revert "Revert "all: remove deprecated usePlaintext(boolean)""
This reverts commit 316a739e67.
2019-11-18 16:53:52 -08:00
Kun Zhang d77419557a
netty: reduce default worker ELG thread number by half, to number of CPU cores (#6439)
This would cut the amount of per-thread direct buffer allocations by half, especially with light traffic. This will also cut the amount of file descriptors that's created per thread by half.

Internal benchmark results (median of 5 runs) doesn't show any significant change:
```
                          Before (STDEV)           After (STDEV)
grpc-java-java-multi-qps-integrity_only
Actual QPS               711,004 (6,246)         704,372 (6,873) 
QPS per Client CPU        23,921   (252)          24,188   (252)

grpc-java-java-multi-throughput-integrity_only
Actual QPS                35,326    (48)          35,294    (29) 
QPS per Client CPU         3,362    (17)           3,440    (13)

grpc-java-java-single-latency-integrity_only
Median latency (us)          127  (2.77)             129  (3.13)

grpc-java-java-single-throughput-integrity_only
Actual QPS                   581 (11.60)             590  (7.08)
QPS per Client CPU           490 (10.98)             498  (5.63)
```
2019-11-18 16:26:37 -08:00
Kun Zhang 89cd64328d
netty: provide an option to lower netty allocator chunk size from 16MB to 2MB (#6407)
This would reduce the amount of direct buffer allocations, especially with light traffic. This should mitigate internal issue b/143075435

The change is currently optional and is only effective if system property "io.grpc.netty.useCustomAllocator" is set to "true" ignoring the case.

Internal benchmark results (median of 5 runs) doesn't show any significant change:
```
                          Before (STDEV)           After (STDEV)
grpc-java-java-multi-qps-integrity_only
Actual QPS               717,848 (7,445)         715,061 (2,122) 
QPS per Client CPU        23,768   (799)          23,842   (295)

grpc-java-java-multi-throughput-integrity_only
Actual QPS                35,631   (204)          35,298    (25) 
QPS per Client CPU         3,362    (56)           3,316    (18)

grpc-java-java-single-latency-integrity_only
Median latency (us)          130  (1.82)             125  (5.36)

grpc-java-java-single-throughput-integrity_only
Actual QPS                    593 (5.14)             587  (3.76)
QPS per Client CPU            502 (4.51)             494  (6.92)

```
2019-11-14 15:50:11 -08:00
Steve Rao 1118793bfb netty: improve code readability (#6375) 2019-11-12 08:48:58 -08:00
Steve Rao a408d086bd netty: unified log prompt (#6386) 2019-11-05 19:47:50 -08:00
Steve Rao 1adf403bb1 netty: remove redundant variable references 2019-11-05 17:48:51 -08:00
Eric Anderson 28149944ad netty: Deflake WriteBufferingAndExceptionHandlerTest
It appears the problem is that server.close() was missing sync(), so the
event loop was still processing the closure when the next test started.

This change is more aggressive than it needs to be, but should make it
less bug-prone.

Fixes #5574
2019-11-04 17:52:57 -08:00
sanjaypujare 48b41dce9e
xds: Client and server proto negotiators and handlers added to SdsProtocolNegotiators (#6319) 2019-10-24 15:27:53 -07:00
Jihun Cho c166ec2c4e netty: use FINE log for pure IOExceptions 2019-10-24 15:17:16 -07:00
ZHANG Dapeng 316a739e67
Revert "all: remove deprecated usePlaintext(boolean)"
This reverts commit 296857b4e7.
2019-10-10 15:56:47 -07:00
ZHANG Dapeng 296857b4e7
all: remove deprecated usePlaintext(boolean) 2019-10-08 09:27:39 -07:00
Eric Anderson 2caa77d48f netty: Implicitly enable Conscrypt when it is available
This implicit loading is more conservative than the loading for
tcnative, as Conscrypt will only be implicitly loaded if there are no
other options. This means the Java 9+ JSSE is preferred over Conscrypt
without explicit user configuration.

While we would generally prefer Conscrypt over JSSE, we want to allow
the user to configure their security providers. There wasn't a good way
to do that with netty-tcnative and the performance of JSSE at the time
was abysmal.

While generally being a good way to allow adopting Conscrypt, this also
allows easily using App Engine Java 8's provided Conscrypt which can
substantially reduce binary size.

See googleapis/google-cloud-java#6425
2019-10-07 11:37:50 -07:00
Jihun Cho e9ac1b4a76
all: update modules to wait until other module's sourceSet is available (#6232) 2019-10-02 15:05:44 -07:00
Carl Mastrangelo ab2aff48dc netty,okhttp,cronet: add option to use get/put when methods are safe/idempotent
This change adds two booleans to the ChannelBuilders to
allow transports to use get and put.   These are currently defaulted to
on, but unset on the method descriptors.   This change is 1/2 that will
allow the safe / idempotent bits to be set on generated proto code.
Part 2/2 will actually enable it.

The use case for this is for interceptors that implement caching logic.
They need to be able to access the safe/idempotent bits on the MD in
order to decide to how to handle the request, even if gRPC doesn't use
GET / PUT HTTP methods.
2019-09-25 14:57:17 -07:00
Eric Anderson bd48891dab netty: Check for TE header after checking Content-Type
Checking too early leads to false-positives, like if a non-gRPC client
contacts the server or a grpc-web client.
2019-09-25 14:04:19 -07:00
Jihun Cho 16392bc733
netty: converts Proxy handler into new protocol negotiation style (#6159) 2019-09-19 15:29:03 -07:00
Anar Sultanov ba0fd84d79 netty: Rely on ChannelFactory in NettyServer instead of dynamic classes
Fixes #5649
2019-09-17 15:59:29 -07:00
Eric Anderson 2b945774b6 Apply animalsniffer plugin explicitly when needed 2019-09-13 09:42:17 -07:00
Eric Anderson 4215b80b81 Apply java plugin explicitly when needed 2019-09-13 09:42:17 -07:00
Eric Anderson e13221b503 Apply japicmp plugin explicitly when needed 2019-09-13 09:42:17 -07:00
Eric Anderson 3b29f74271 Move ALPN Agent configuration to each project needing it 2019-09-13 09:42:17 -07:00
Eric Anderson 5b838e5284 Apply maven-publish plugin explicitly when needed 2019-09-13 09:42:17 -07:00
Eric Anderson 55ac6f08af Apply JMH plugin explicitly when needed 2019-09-13 09:42:17 -07:00
Eric Anderson 3c3a823a81 Swap to Gradle's Plugin DSL for much of build
Examples and android projects were left unchanged. They can be changed
later.

No plugin versions were changed, to make this as non-functional of a
change as possible. Upgrading Gradle to 5.6 was necessary for
pluginManagement in settings.gradle.
2019-09-13 09:42:17 -07:00
康智冬 415212fc49 alts: fix typo (#6113) 2019-09-10 14:13:35 -07:00
Eric Anderson 9d6f5322c2 bazel: Add helper for maven_install's override_targets
This can be used to prevent duplicate classes in the classpath, one via
Maven and one via Bazel-native.

See census-instrumentation/opencensus-java#1963 and #5359
2019-08-22 07:40:32 -07:00
Eric Anderson 63661c7b70 netty: Add Bazel target similar to netty-shaded
See census-instrumentation/opencensus-java#1963
2019-08-21 09:48:20 -07:00
Carl Mastrangelo 21c34d7862
netty: check for null protocol negotiator in NettyChannelBuilder 2019-08-15 11:11:31 -07:00
Carl Mastrangelo 458f4533db
netty: migrate Server protocol negotiation to new style
* Revert "Revert "netty: change server to new protocol negotiator model" (#5798)"

This reverts commit 4e5e19f6fd.
2019-08-14 13:00:42 -07:00
Eric Anderson 9fcfb5b4f8
netty: Limit number of frames client can cause server to enqueue
Http2ControlFrameLimitEncoder is from Netty. It is copied here as a
temporary measure until we upgrade to the version of Netty that includes
the class.

See CVE-2019-9515
2019-08-13 12:24:15 -05:00
Laurent Le Brun 503696aa9a bazel: Remove missing pattern from glob
There's no third_party directory.
This change makes the repository compatible with
Bazel change --incompatible_disallow_empty_glob.
2019-08-08 16:41:17 -07:00
Jihun Cho 4faad27078
netty: record ByteBuf access in Netty{Client,Server}Stream before calling MessageDeframer (#6027) 2019-08-02 16:25:08 -07:00
Jihun Cho 65109e6738
netty: Netty{Server,Channel}Builder requires all or none of ELG and ChannelType (#6014) 2019-07-26 09:25:02 -07:00
Carl Mastrangelo cc524f10d3
netty,interop-testing: increase timeouts on tests for TSAN 2019-07-19 15:24:19 -07:00
Carl Mastrangelo 25a72e1f6d
netty: don't share transport tracers across transports
Found using TSAN, which shows the number of calls succeeded being incremented from multiple event loops
2019-07-15 11:18:35 -07:00
Carl Mastrangelo 855740622a
all: bump PerfMark to 0.17.0
* Bump PerfMark to 0.17.0

The main changes how linking is done.  Linking is now always done
through the `PerfMark` entry class.   This is for two reasons:

1.  It make instrumenting the linking calls *much* easier.
2.  It follows the API pattern of "verbNoun()".  Previous callsites
    would have `Link link = PerfMark.link(); link.link()`.  This
    stuttering is not quick to follow.

Generated using:

```
find -name \*.java -exec sed -i 's#link = PerfMark.link();#link = PerfMark.linkOut();#g' {} \;
find -name \*.java -exec sed -i 's#link.link();#PerfMark.linkIn(link);#g' {} \;
find -name \*.java -exec sed -i 's#command.getLink().link();#PerfMark.linkIn(command.getLink());#g' {} \;
find -name \*.java -exec sed -i 's#cmd.getLink().link();#PerfMark.linkIn(cmd.getLink());#g' {} \;
find -name \*.java -exec sed -i 's#msg.getLink().link();#PerfMark.linkIn(msg.getLink());#g' {} \;
```

Since the deprecated link methods are also `@DoNotCall`, the same
sed calls will need to be used on import.
2019-07-11 10:57:05 -07:00
Carl Mastrangelo 9aa3981ada
netty: use varargs logger in ProtocolNegotiators 2019-06-27 15:59:43 -07:00
Carl Mastrangelo 023b9a3f14
netty: don't use InternalProtocolNegotiators in ProtocolNegotiators 2019-06-27 15:07:43 -07:00
Carl Mastrangelo 0a1805db43
netty: include pipeline on exceptions too 2019-06-27 13:04:31 -07:00
Carl Mastrangelo 9e5f60b86a
netty: upstream ProtocolNegotiatiorHandler, and swap the appropriate classes to it
ALTS is not switched yet, since it is shared between client and server. Once the server is changed to use WBAEH, it can be moved too.
2019-06-26 18:23:12 -07:00
Carl Mastrangelo 7895c33efa
netty: make unexpected reads fail negotiation, and log close failures
In case a negotiating handler misses a read, and it reaches the WBAEH, it should cause a failure. Also, if closing the channel fails while handling another error, log the second failure.
2019-06-26 14:43:06 -07:00
ZHANG Dapeng 18645422c9
netty: Delete deprecated HandlerSettings 2019-06-20 11:34:19 -07:00
Eric Anderson 29cb7c4dd4 netty: Use await instead of sync
We only care about when closing is done, not whether it is successful or not.
If there's a failure, we're already going to log a warning. Use await to avoid
throwing unexpectedly.
2019-06-20 07:19:56 -07:00
Carl Mastrangelo 74e945ceb4
core,netty: block server shutdown until the socket is unbound 2019-06-19 17:23:08 -07:00
Eric Anderson 3d289213ce
netty-shaded: Use compile instead of runtime dependency in pom (#5901)
Maven does not include transitive runtime dependencies in the
compile-time classpath (testing shows Gradle 4 does; docs say
Gradle 5 doesn't). So if a user references the shaded
NettyServerBuilder without also depending on grpc-core directly,
compilation will fail because AbstractServerImplBuilder couldn't
be found.

This isn't technically a problem, since we're not wanting to encourage
users to reference the shaded classes directly. But some users will
certainly reference the classes anyway and the error is pretty confusing
while also being trivially worked around. In other words: it justs
wastes people's time and benefits nobody.

Fixes #5881
2019-06-19 09:51:00 -07:00
Carl Mastrangelo 9c9ca659d4
netty,alts: fire initial protocol negotiation event in WBAEH
This change is needed after trying to use the new style protocol negotiators internally.  The problem is that some handlers fire the event in handlerAdded, which is too early.  The followup PNE is fired after handlerAdded, which breaks the composibility of the negotiators.

To fix this, this change modifies the negotiation flow.  Specifically:

* Negotiators should NEVER fire a negotiation from handlerAdded, instead they should wait until userEventTriggered
* Negotiators now do state checking on the PNE.  If it is set twice, it fails.  If it has not been received when doing the next stage of negotiation, it fails.
* WBAEH now fires the initial, default event.  This is the only handler that can fire it from handlerAdded

The tests updated are ones not using WBAEH (which they probably should).  This change ensures attributes aren't lost when doing negotiation.
2019-06-18 09:33:40 -07:00
Carl Mastrangelo 40854dc9e1
core,netty: use PerfMark tags with the HTTP/2 stream ids
This change removes the WriteQueue linking and splits it out into each
of the commands, so that the trace is more precise, and the tag
information is correct.

It is still unclear what the initial Tag should be for ClientCallImpl,
since it should not access the TransportState to get the HTTP/2 stream id.
2019-06-17 15:25:39 -07:00
Carl Mastrangelo e5bd7f282c
Revert "Revert "core, netty: add io.perfmark Annotations" (#5853)" (#5884)
This reverts commit 2db3abc9ad.
2019-06-14 14:09:05 -07:00
Nick Travers 6aed34231f netty: refine filtering for benign transport level exceptions
Transport level exceptions (e.g. "Connection reset by peer") are not
useful and clutter the logs. `NettyServerTransport` contains logic to
log such exceptions at level `FINE`.

When running with epoll, transport level exceptions are prefixed with
additional contextual information (e.g. "syscall:read(..) failed:") that
causes the exceptions to be logged at level `INFO`.

Update the filtering logic to match on error messages _containing_ the
blacklisted messages, rather than using string equality.

Closes #5872.

Signed-off-by: Nick Travers <n.e.travers@gmail.com>
2019-06-13 09:24:36 -07:00
Carl Mastrangelo 2db3abc9ad
Revert "core, netty: add io.perfmark Annotations" (#5853)
This causes internal breakage which needs to be resolved before continuing.

This reverts commit 71967622d6.
2019-06-07 17:23:49 -07:00
Carl Mastrangelo 71967622d6
core, netty: add io.perfmark Annotations
This add perfmark annotations in some key places, notably on transport/application boundaries, and thread hop locations. Perfmark records to a thread-local buffer the events that happen in each thread. Perfmark is disabled by default, and will compile to a noop unless Perfmark.setEnabled is invoked. This should make it free when disable, and pretty fast when it is enabled.

It is important that started tasks are ended, so several places in our code are moved to either try-finally blocks, or moved into a private method. I realize this is ugly, but I think it is manageable. In the future, we can look at making an agent or compiler plugin that simplifies the recording.

Linking between threads is done with a Link object, which is created on the "outbound" task, and used on the "inbound" task. This is slightly more verbose, and does has a small amount of runtime overhead, even when disabled. (for null checks, slightly higher memory usage, etc.) I think this is okay to, because it makes other optimizations much easier.
2019-06-06 17:58:49 -07:00
Carl Mastrangelo 8536832232
core,netty: expose server stream id 2019-06-06 13:52:22 -07:00
Carl Mastrangelo 7657523b28
all: update to error prone 2.3.3 2019-06-05 15:28:43 -07:00
Carl Mastrangelo 4e5e19f6fd
Revert "netty: change server to new protocol negotiator model" (#5798)
This reverts commit f94b77c87f.
2019-05-28 21:12:25 -07:00
Eric Anderson 2cbc540cb3 Remove deprecated enableKeepAlive API from transports
As mentioned in 5188[1], the default used with the enableKeepAlive API
conflicted with the default server enforcement. Instead of fixing it,
remove it. These APIs were deprecated in v1.3.0 in April 2017.

1. https://github.com/grpc/grpc-java/issues/5188#issuecomment-482269303
2019-05-28 16:37:02 -07:00
Carl Mastrangelo 7834a50525
alts: use new ProtocolNegotiator style for ALTS
This change does a few core things, which result in a lot of churn in other parts.  It's not as bad as it seems.

Core things:

1.  AltsProtocolNegotiator is now a shim class, same as ProtocolNegotiators
2.  The protocol negotiators are now in the new style, where there is at most 1 negotiation handler in the pipe at a time.
3.  TsiHandshakeHandler is rewritten with respect to the above.  All errors and buffering are handled by the WBAEH.
4.  TsiFrameHandler is only installed once the negotiation is successful, eliminating the state handling.


The churn in mainly in GoogleDefaultChannel and the GCE channel, which now reuse the *handlers* rather than the negotiators.  This makes it significantly easier to reason about the pipeline state.  The tests are also a source of churn, which no long need to check for most buffering and error conditions.
2019-05-22 16:33:07 -07:00
Carl Mastrangelo f94b77c87f
netty: change server to new protocol negotiator model
Changes:

* PlaintextProtocolNegotiator is the same between client and server
* ServerTlsHandler is rewritten to not handle errors 
  * Also, it now sets the security level attribute, which I don't think it did previously
* NettyServerTransport now uses WBAEH, similar to the client. I don't think the buffer is needed, but it does  correctly handle errors during the startup
2019-05-16 18:15:47 -07:00
Carl Mastrangelo ae4d7a944a
netty: provide methods for logging protocol negotiation 2019-05-10 18:22:32 -07:00
NickUfer 6807f39155 Removes the class `io.grpc.internal.MoreThrowables` and replaces it with
`com.google.common.base.Throwables`
2019-05-02 14:23:09 -07:00
Jihun Cho f4fb7b40c5
netty: set NettyServer default socket options for all Channels (#5651) 2019-05-01 11:29:03 -07:00
Jihun Cho 6a32c508b8
netty: fix TCP_USER_TIMEOUT to use keepAliveTimeout instead of keepAliveTime (#5645) 2019-04-26 16:02:58 -07:00
Jihun Cho 67ef8c3466
netty: not using reflection to create NioEventLoopGroup (#5630) 2019-04-23 16:45:19 -07:00
Carl Mastrangelo 04e07034f3
all: update to truth 0.44 2019-04-23 10:50:49 -07:00
Jihun Cho dc0171839a
netty: add internal API to fall back to NIO transport (#5611) 2019-04-18 13:49:55 -07:00