Search in sources :

Example 16 with ConnectionException

use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.

the class TestS6x5SettingsFrameErrors method testSection6_5AckNonEmptyPayload.

@Test
public void testSection6_5AckNonEmptyPayload() {
    String badAckFrame = // length
    "00 00 01" + // type
    "04" + // flags (ack)
    "01" + // R + streamid
    "00 00 00 00" + // payload
    "00";
    // ack client frame
    mockChannel.sendHexBack(badAckFrame);
    // remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: stream0:(FRAME_SIZE_INCORRECT) size of payload of a settings frame ack must be 0 but was=1", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 17 with ConnectionException

use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.

the class Level2ParsingAndRemoteSettings method handleFinalError.

private Void handleFinalError(Object object, Throwable e) {
    if (e == null)
        return null;
    else if (e instanceof ConnectionException) {
        log.error("shutting the connection down due to error", e);
        ConnectionFailure reset = new ConnectionFailure((ConnectionException) e);
        // send GoAway
        syncro.sendGoAwayToSvrAndResetAllToApp(reset).exceptionally(t -> logExc("connection", t));
    } else if (e instanceof StreamException) {
        log.error("Stream had an error", e);
        streamsToDiscard.add(((StreamException) e).getStreamId());
        syncro.sendRstToServerAndApp((StreamException) e).exceptionally(t -> logExc("stream", t));
    } else {
        log.error("shutting the connection down due to error(MAKE sure your clients try..catch, exceptions)", e);
        ConnectionException exc = new ConnectionException(CancelReasonCode.BUG, logId, 0, e.getMessage(), e);
        ConnectionFailure reset = new ConnectionFailure((ConnectionException) exc);
        // send GoAwa
        syncro.sendGoAwayToSvrAndResetAllToApp(reset).exceptionally(t -> logExc("connection", t));
    }
    return null;
}
Also used : WindowUpdateFrame(com.webpieces.http2.api.dto.lowlevel.WindowUpdateFrame) PriorityFrame(com.webpieces.http2.api.dto.lowlevel.PriorityFrame) RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) Http2Config(com.webpieces.http2engine.api.client.Http2Config) LoggerFactory(org.slf4j.LoggerFactory) UnknownFrame(com.webpieces.http2.api.dto.lowlevel.UnknownFrame) ByteAckTracker(org.webpieces.util.acking.ByteAckTracker) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) PingFrame(com.webpieces.http2.api.dto.lowlevel.PingFrame) HpackParser(com.webpieces.hpack.api.HpackParser) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException) UnmarshalState(com.webpieces.hpack.api.UnmarshalState) DataWrapper(org.webpieces.data.api.DataWrapper) SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) ConnectionClosedException(com.webpieces.http2engine.api.error.ConnectionClosedException) Logger(org.slf4j.Logger) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) ConnectionFailure(com.webpieces.http2engine.api.error.ConnectionFailure) CancelReasonCode(com.webpieces.http2.api.dto.error.CancelReasonCode) List(java.util.List) StreamException(com.webpieces.http2.api.dto.error.StreamException) ReceivedGoAway(com.webpieces.http2engine.api.error.ReceivedGoAway) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) XFuture(org.webpieces.util.futures.XFuture) Http2Trailers(com.webpieces.http2.api.dto.highlevel.Http2Trailers) ConnectionFailure(com.webpieces.http2engine.api.error.ConnectionFailure) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException) StreamException(com.webpieces.http2.api.dto.error.StreamException)

Example 18 with ConnectionException

use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.

the class Level6RemoteFlowControl method updateStreamWindowSize.

public XFuture<Void> updateStreamWindowSize(Stream stream, WindowUpdateFrame msg) {
    if (msg.getWindowSizeIncrement() == 0) {
        throw new ConnectionException(CancelReasonCode.WINDOW_SIZE_INVALID, logId, msg.getStreamId(), "Received windowUpdate size increment=0");
    }
    DataTry dataTry = null;
    DataTry temp = dataQueue.peek();
    synchronized (remoteLock) {
        long remoteWindowSize = stream.incrementRemoteWindow(msg.getWindowSizeIncrement());
        if (temp != null && remoteWindowSize > temp.getDataFrame().getTransmitFrameLength())
            dataTry = dataQueue.poll();
        log.info("updated stream " + stream.getStreamId() + " window to=" + stream.getRemoteWindowSize() + " increment=" + msg.getWindowSizeIncrement() + " dataTry to submit=" + dataTry);
    }
    if (dataTry != null) {
        dataTry.setWasQueuedBefore(true);
        trySendPayload(dataTry);
    }
    // someday, remove synchronized above and then complete future when it is complete instead maybe
    return XFuture.completedFuture(null);
}
Also used : DataTry(com.webpieces.http2engine.impl.DataTry) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 19 with ConnectionException

use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.

the class Level6RemoteFlowControl method updateConnectionWindowSize.

public XFuture<Void> updateConnectionWindowSize(WindowUpdateFrame msg) {
    int increment = msg.getWindowSizeIncrement();
    if (increment == 0) {
        throw new ConnectionException(CancelReasonCode.WINDOW_SIZE_INVALID, logId, msg.getStreamId(), "Received windowUpdate size increment=0");
    }
    DataTry dataTry = null;
    DataTry temp = dataQueue.peek();
    synchronized (remoteLock) {
        // TODO: Use AsyncLock instead so we do not block threads!!!
        remoteWindowSize += increment;
        if (remoteWindowSize > Integer.MAX_VALUE)
            throw new ConnectionException(CancelReasonCode.FLOW_CONTROL_ERROR, logId, 0, "(remote end bad)global remoteWindowSize too large=" + remoteWindowSize + " from windows increment=" + increment);
        if (temp != null && remoteWindowSize > temp.getDataFrame().getTransmitFrameLength())
            dataTry = dataQueue.poll();
        log.info("updated window to=" + remoteWindowSize + " increment=" + msg.getWindowSizeIncrement() + " dataTry to submit=" + dataTry);
    }
    if (dataTry != null) {
        dataTry.setWasQueuedBefore(true);
        trySendPayload(dataTry);
    }
    return XFuture.completedFuture(null);
}
Also used : DataTry(com.webpieces.http2engine.impl.DataTry) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 20 with ConnectionException

use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.

the class TestC4FrameSizeAndHeaders method testSection4_2FrameTooLarge.

/**
 * An endpoint MUST send an error code of FRAME_SIZE_ERROR if a frame
 * exceeds the size defined in SETTINGS_MAX_FRAME_SIZE, exceeds any
 * limit defined for the frame type, or is too small to contain
 * mandatory frame data. A frame size error in a frame that could alter
 * the state of the entire connection MUST be treated as a connection
 * error (Section 5.4.1); this includes any frame carrying a header
 * block (Section 4.3) (that is, HEADERS, PUSH_PROMISE, and
 * CONTINUATION), SETTINGS, and any frame with a stream identifier of 0.
 */
@Test
public void testSection4_2FrameTooLarge() {
    MockStreamWriter mockStreamWriter = new MockStreamWriter();
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(mockStreamWriter));
    Http2Request request = sendRequestToServer(listener1);
    sendResponseFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    byte[] buf = new byte[localSettings.getMaxFrameSize() + 4];
    dataFrame.setData(DATA_GEN.wrapByteArray(buf));
    // endOfStream=false
    mockChannel.write(dataFrame);
    // remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.FRAME_SIZE_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: stream1:(EXCEEDED_MAX_FRAME_SIZE) Frame size=16389 was greater than max=16385", msg);
    Assert.assertTrue(mockChannel.isClosed());
    ShutdownStream failResp = (ShutdownStream) listener1.getSingleRstStream();
    Assert.assertEquals(CancelReasonCode.EXCEEDED_MAX_FRAME_SIZE, failResp.getCause().getReasonCode());
    // send new request on closed connection
    Http2Request request1 = Requests.createRequest();
    StreamRef streamRef = httpSocket.openStream().process(request1, listener1);
    XFuture<StreamWriter> future = streamRef.getWriter();
    ConnectionClosedException intercept = (ConnectionClosedException) TestAssert.intercept(future);
    Assert.assertTrue(intercept.getMessage().contains("Connection closed or closing"));
    Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
}
Also used : MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) ConnectionClosedException(com.webpieces.http2engine.api.error.ConnectionClosedException) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) Test(org.junit.Test)

Aggregations

ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)26 DataWrapper (org.webpieces.data.api.DataWrapper)18 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)15 Test (org.junit.Test)13 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)12 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)8 ByteBuffer (java.nio.ByteBuffer)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)6 ConnectionClosedException (com.webpieces.http2engine.api.error.ConnectionClosedException)6 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)6 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 FrameHeaderData (com.webpieces.http2parser.impl.FrameHeaderData)5 StreamRef (com.webpieces.http2.api.streaming.StreamRef)4 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)4 StreamException (com.webpieces.http2.api.dto.error.StreamException)3 HeadersFrame (com.webpieces.http2.api.dto.lowlevel.HeadersFrame)3 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)3 PriorityDetails (com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails)3 DataSplit (com.webpieces.http2parser.impl.DataSplit)3 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)2