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());
}
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;
}
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);
}
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);
}
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());
}
Aggregations