Refine search
private static void processGoAwayWriteResult(final ChannelHandlerContext ctx, final int lastStreamId, final long errorCode, final ByteBuf debugData, ChannelFuture future) { try { if (future.isSuccess()) { if (errorCode != NO_ERROR.code()) { if (logger.isDebugEnabled()) { logger.debug("{} Sent GOAWAY: lastStreamId '{}', errorCode '{}', " + "debugData '{}'. Forcing shutdown of the connection.", ctx.channel(), lastStreamId, errorCode, debugData.toString(UTF_8), future.cause()); } ctx.close(); } } else { if (logger.isDebugEnabled()) { logger.debug("{} Sending GOAWAY failed: lastStreamId '{}', errorCode '{}', " + "debugData '{}'. Forcing shutdown of the connection.", ctx.channel(), lastStreamId, errorCode, debugData.toString(UTF_8), future.cause()); } ctx.close(); } } finally { // We're done with the debug data now. debugData.release(); } }
@Override public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception { Http2Stream stream = connection.stream(streamId); FullHttpMessage msg = getMessage(stream); if (msg != null) { onRstStreamRead(stream, msg); } ctx.fireExceptionCaught(Http2Exception.streamError(streamId, Http2Error.valueOf(errorCode), "HTTP/2 to HTTP layer caught stream reset")); }
protected static void incrementErrorCounter(Registry registry, String counterName, String metricId, Http2Exception h2e) { String h2Error = h2e.error() != null ? h2e.error().name() : "NA"; String exceptionName = h2e.getClass().getSimpleName(); registry.counter(counterName, "id", metricId, "error", h2Error, "exception", exceptionName) .increment(); }
@Override protected void onConnectionError(ChannelHandlerContext ctx, Throwable cause, Http2Exception connectionError) { // Logs the full exception here final String message = String.format( "HTTP/2 connection encountered an exception, streamCount=%d, remote=%s, channel=%s", connection().numActiveStreams(), ctx.channel().remoteAddress(), ctx.channel().id()); LOG.error(message, cause); try { connection().forEachActiveStream(stream -> { resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise()); doOnStreamError(ctx, stream.id(), cause); return true; }); ctx.flush(); } catch (Http2Exception e) { LOG.error("Encountered exception while invoking request callbacks with errors", e); } finally { super.onConnectionError(ctx, cause, connectionError); } }
encoder.writeRstStream(ctx, streamId, Http2Error.CANCEL.code(), ctx.newPromise()); ctx.flush(); } else {
@Override protected ChannelFuture doWriteReset(int id, int streamId, Http2Error error) { final Http2Stream stream = encoder.connection().stream(streamId); // Send a RST_STREAM frame only for an active stream which did not send a RST_STREAM frame already. if (stream != null && !stream.isResetSent()) { return encoder.writeRstStream(ctx, streamId, error.code(), ctx.newPromise()); } return ctx.writeAndFlush(Unpooled.EMPTY_BUFFER); }
@Override public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) { LOG.warn("RST received on channel: {} for streamId: {} errorCode: {}", http2ClientChannel, streamId, errorCode); Http2Reset http2Reset = new Http2Reset(streamId, Http2Error.valueOf(errorCode)); ctx.fireChannelRead(http2Reset); }
/** * Close the remote endpoint with with a {@code GO_AWAY} frame. Does <strong>not</strong> flush * immediately, this is the responsibility of the caller. */ private ChannelFuture goAway(ChannelHandlerContext ctx, Http2Exception cause) { long errorCode = cause != null ? cause.error().code() : NO_ERROR.code(); int lastKnownStream = connection().remote().lastStreamCreated(); return goAway(ctx, lastKnownStream, errorCode, Http2CodecUtil.toByteBuf(ctx, cause), ctx.newPromise()); }
if (isWritable(stream)) { writeErrorResponse(ctx, streamId, HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE); writer.writeRstStream(ctx, streamId, Http2Error.CANCEL.code(), ctx.voidPromise()); if (req.isOpen()) { req.close(ContentTooLargeException.get());
/** * Equivalent to {@code new DefaultHttp2GoAwayFrame(error.code())}. * * @param error non-{@code null} reason for the go away */ public DefaultHttp2GoAwayFrame(Http2Error error) { this(error.code()); }
@Override public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception { final DecodedHttpRequest req = requests.get(streamId); if (req == null) { throw connectionError(PROTOCOL_ERROR, "received a RST_STREAM frame for an unknown stream: %d", streamId); } req.abortResponse(streamError( streamId, Http2Error.valueOf(errorCode), "received a RST_STREAM frame")); }
ctx.write(msg, promise); return; LOG.debug("Sent HTTP/2 DATA frame, stream={}, end={}, data={}bytes, padding={}bytes", new Object[]{streamId, END_STREAM, data.readableBytes(), NO_PADDING}); encoder.writeData(ctx, streamId, data, NO_PADDING, END_STREAM, ctx.newPromise()); ctx.channel().flush(); resetStream(ctx, streamId, Http2Error.CANCEL.code(), ctx.newPromise()); ctx.flush(); }); resetStream(ctx, streamId, Http2Error.CANCEL.code(), ctx.newPromise()); ctx.flush();
private void doReset() { // Resets and closes the stream _lifecycleManager.resetStream(_ctx, _streamId, Http2Error.CANCEL.code(), _ctx.newPromise()); _ctx.flush(); // Releases the handle to put the channel back to the pool _timeoutPoolHandle.release(); }
stream = encoder.connection().remote().createStream(streamId, true); } catch (Http2Exception e) { resetUnknownStream(ctx, streamId, http2Ex.error().code(), ctx.newPromise()); return; resetUnknownStream(ctx, streamId, http2Ex.error().code(), ctx.newPromise()); resetStream(ctx, stream, http2Ex.error().code(), ctx.newPromise());
/** * * * @param error non-{@code null} reason for the go away * @param content non-{@code null} debug data */ public DefaultHttp2GoAwayFrame(Http2Error error, ByteBuf content) { this(error.code(), content); }
@Override public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception { final DefaultHttpRequest req = requests.get(streamId); if (req == null) { throw connectionError(PROTOCOL_ERROR, "received a RST_STREAM frame for an unknown stream: %d", streamId); } req.close(streamError(streamId, Http2Error.valueOf(errorCode), "received a RST_STREAM frame")); }
private static void processGoAwayWriteResult(final ChannelHandlerContext ctx, final int lastStreamId, final long errorCode, final ByteBuf debugData, ChannelFuture future) { try { if (future.isSuccess()) { if (errorCode != NO_ERROR.code()) { if (logger.isDebugEnabled()) { logger.debug("{} Sent GOAWAY: lastStreamId '{}', errorCode '{}', " + "debugData '{}'. Forcing shutdown of the connection.", ctx.channel(), lastStreamId, errorCode, debugData.toString(UTF_8), future.cause()); } ctx.close(); } } else { if (logger.isDebugEnabled()) { logger.debug("{} Sending GOAWAY failed: lastStreamId '{}', errorCode '{}', " + "debugData '{}'. Forcing shutdown of the connection.", ctx.channel(), lastStreamId, errorCode, debugData.toString(UTF_8), future.cause()); } ctx.close(); } } finally { // We're done with the debug data now. debugData.release(); } }