List of usage examples for io.netty.handler.codec.http2 Http2Error ENHANCE_YOUR_CALM
Http2Error ENHANCE_YOUR_CALM
To view the source code for io.netty.handler.codec.http2 Http2Error ENHANCE_YOUR_CALM.
Click Source Link
From source file:io.grpc.netty.Http2ControlFrameLimitEncoder.java
License:Apache License
private ChannelPromise handleOutstandingControlFrames(ChannelHandlerContext ctx, ChannelPromise promise) { if (!limitReached) { if (outstandingControlFrames == maxOutstandingControlFrames) { // Let's try to flush once as we may be able to flush some of the control frames. ctx.flush();//from w ww . java 2s . com } if (outstandingControlFrames == maxOutstandingControlFrames) { limitReached = true; Http2Exception exception = Http2Exception.connectionError(Http2Error.ENHANCE_YOUR_CALM, "Maximum number %d of outstanding control frames reached", maxOutstandingControlFrames); logger.info("Maximum number {} of outstanding control frames reached. Closing channel {}", maxOutstandingControlFrames, ctx.channel(), exception); // First notify the Http2LifecycleManager and then close the connection. lifecycleManager.onError(ctx, true, exception); ctx.close(); } outstandingControlFrames++; // We did not reach the limit yet, add the listener to decrement the number of outstanding control frames // once the promise was completed return promise.unvoid().addListener(outstandingControlFramesListener); } return promise; }
From source file:io.grpc.netty.NettyClientHandler.java
License:Apache License
private NettyClientHandler(Http2ConnectionDecoder decoder, StreamBufferingEncoder encoder, Http2Settings settings, ClientTransportLifecycleManager lifecycleManager, KeepAliveManager keepAliveManager, Supplier<Stopwatch> stopwatchFactory, final Runnable tooManyPingsRunnable, TransportTracer transportTracer, Attributes eagAttributes, String authority) {/* w w w. j av a 2s .c o m*/ super(/* channelUnused= */ null, decoder, encoder, settings); this.lifecycleManager = lifecycleManager; this.keepAliveManager = keepAliveManager; this.stopwatchFactory = stopwatchFactory; this.transportTracer = Preconditions.checkNotNull(transportTracer); this.eagAttributes = eagAttributes; this.authority = authority; this.attributes = Attributes.newBuilder().set(GrpcAttributes.ATTR_CLIENT_EAG_ATTRS, eagAttributes).build(); // Set the frame listener on the decoder. decoder().frameListener(new FrameListener()); Http2Connection connection = encoder.connection(); streamKey = connection.newKey(); connection.addListener(new Http2ConnectionAdapter() { @Override public void onGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData) { byte[] debugDataBytes = ByteBufUtil.getBytes(debugData); goingAway(statusFromGoAway(errorCode, debugDataBytes)); if (errorCode == Http2Error.ENHANCE_YOUR_CALM.code()) { String data = new String(debugDataBytes, UTF_8); logger.log(Level.WARNING, "Received GOAWAY with ENHANCE_YOUR_CALM. Debug data: {1}", data); if ("too_many_pings".equals(data)) { tooManyPingsRunnable.run(); } } } @Override public void onStreamActive(Http2Stream stream) { if (connection().numActiveStreams() == 1 && NettyClientHandler.this.keepAliveManager != null) { NettyClientHandler.this.keepAliveManager.onTransportActive(); } } @Override public void onStreamClosed(Http2Stream stream) { // Although streams with CALL_OPTIONS_RPC_OWNED_BY_BALANCER are not marked as "in-use" in // the first place, we don't propagate that option here, and it's safe to reset the in-use // state for them, which will be a cheap no-op. inUseState.updateObjectInUse(stream, false); if (connection().numActiveStreams() == 0 && NettyClientHandler.this.keepAliveManager != null) { NettyClientHandler.this.keepAliveManager.onTransportIdle(); } } }); }
From source file:io.grpc.netty.NettyServerHandlerTest.java
License:Apache License
@Test public void keepAliveEnforcer_enforcesPings() throws Exception { permitKeepAliveWithoutCalls = false; permitKeepAliveTimeInNanos = TimeUnit.HOURS.toNanos(1); manualSetUp();/*from w w w . j av a2s . com*/ for (int i = 0; i < KeepAliveEnforcer.MAX_PING_STRIKES + 1; i++) { channelRead(pingFrame(false /* isAck */, 1L)); } verifyWrite().writeGoAway(eq(ctx()), eq(0), eq(Http2Error.ENHANCE_YOUR_CALM.code()), any(ByteBuf.class), any(ChannelPromise.class)); assertFalse(channel().isActive()); }
From source file:io.grpc.netty.NettyServerHandlerTest.java
License:Apache License
@Test public void keepAliveEnforcer_sendingDataResetsCounters() throws Exception { permitKeepAliveWithoutCalls = false; permitKeepAliveTimeInNanos = TimeUnit.HOURS.toNanos(1); manualSetUp();//from ww w . j a v a 2s . c o m createStream(); Http2Headers headers = Utils.convertServerHeaders(new Metadata()); ChannelFuture future = enqueue(SendResponseHeadersCommand.createHeaders(stream.transportState(), headers)); future.get(); for (int i = 0; i < 10; i++) { future = enqueue(new SendGrpcFrameCommand(stream.transportState(), content().retainedSlice(), false)); future.get(); channel().releaseOutbound(); channelRead(pingFrame(false /* isAck */, 1L)); } verifyWrite(never()).writeGoAway(eq(ctx()), eq(STREAM_ID), eq(Http2Error.ENHANCE_YOUR_CALM.code()), any(ByteBuf.class), any(ChannelPromise.class)); }
From source file:io.grpc.netty.NettyServerHandlerTest.java
License:Apache License
@Test public void keepAliveEnforcer_initialIdle() throws Exception { permitKeepAliveWithoutCalls = false; permitKeepAliveTimeInNanos = 0;/*from ww w . ja v a2s. c o m*/ manualSetUp(); for (int i = 0; i < KeepAliveEnforcer.MAX_PING_STRIKES + 1; i++) { channelRead(pingFrame(false /* isAck */, 1L)); } verifyWrite().writeGoAway(eq(ctx()), eq(0), eq(Http2Error.ENHANCE_YOUR_CALM.code()), any(ByteBuf.class), any(ChannelPromise.class)); assertFalse(channel().isActive()); }
From source file:io.grpc.netty.NettyServerHandlerTest.java
License:Apache License
@Test public void keepAliveEnforcer_noticesActive() throws Exception { permitKeepAliveWithoutCalls = false; permitKeepAliveTimeInNanos = 0;//from ww w. ja v a2 s . co m manualSetUp(); createStream(); for (int i = 0; i < 10; i++) { channelRead(pingFrame(false /* isAck */, 1L)); } verifyWrite(never()).writeGoAway(eq(ctx()), eq(STREAM_ID), eq(Http2Error.ENHANCE_YOUR_CALM.code()), any(ByteBuf.class), any(ChannelPromise.class)); }
From source file:io.grpc.netty.NettyServerHandlerTest.java
License:Apache License
@Test public void keepAliveEnforcer_noticesInactive() throws Exception { permitKeepAliveWithoutCalls = false; permitKeepAliveTimeInNanos = 0;/*from w w w . j a v a 2 s. c om*/ manualSetUp(); createStream(); channelRead(rstStreamFrame(STREAM_ID, (int) Http2Error.CANCEL.code())); for (int i = 0; i < KeepAliveEnforcer.MAX_PING_STRIKES + 1; i++) { channelRead(pingFrame(false /* isAck */, 1L)); } verifyWrite().writeGoAway(eq(ctx()), eq(STREAM_ID), eq(Http2Error.ENHANCE_YOUR_CALM.code()), any(ByteBuf.class), any(ChannelPromise.class)); assertFalse(channel().isActive()); }