Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jetty-9.4.x-5605-wakeup-blocked-…
Browse files Browse the repository at this point in the history
…threads' into jetty-10.0.x-5605-wakeup-blocked-threads
  • Loading branch information
lorban committed Feb 8, 2021
2 parents 4c67b88 + ed534b8 commit 9611a25
Show file tree
Hide file tree
Showing 8 changed files with 718 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ private boolean parseRequestBuffer()

private boolean upgrade()
{
// If we are fill interested, then a read is pending and we must abort
if (isFillInterested())
{
LOG.warn("Pending read in onCompleted {} {}", this, getEndPoint());
abort(new IllegalStateException());
}

Connection connection = (Connection)_channel.getRequest().getAttribute(UPGRADE_CONNECTION_ATTRIBUTE);
if (connection == null)
return false;
Expand Down Expand Up @@ -416,6 +423,9 @@ public void onCompleted()
if (upgrade())
return;

// Drive to EOF, EarlyEOF or Error
boolean complete = _input.consumeAll();

// Finish consuming the request
// If we are still expecting
if (_channel.isExpecting100Continue())
Expand All @@ -424,7 +434,7 @@ public void onCompleted()
_parser.close();
}
// else abort if we can't consume all
else if (_generator.isPersistent() && !_input.consumeAll())
else if (_generator.isPersistent() && !complete)
{
if (LOG.isDebugEnabled())
LOG.debug("unconsumed input {} {}", this, _parser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public boolean consumeAll()
if (isFinished())
return !isError();

//TODO move to early EOF and notify blocking reader
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;
import java.util.ResourceBundle;
import java.util.concurrent.CancellationException;
import java.util.concurrent.TimeUnit;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletOutputStream;
Expand Down Expand Up @@ -435,10 +437,22 @@ public void complete(Callback callback)
case BLOCKED:
case UNREADY:
case PENDING:
LOG.warn("Pending write in complete {} {}", this, _channel);
// An operation is in progress, so we soft close now
_softClose = true;
// then trigger a close from onWriteComplete
_state = State.CLOSE;

// But if we are blocked or there is more content to come, we must abort
// Note that this allows a pending async write to complete only if it is the last write
if (_apiState == ApiState.BLOCKED || !_channel.getResponse().isContentComplete(_written))
{
CancellationException cancelled = new CancellationException();
_writeBlocker.fail(cancelled);
_channel.abort(cancelled);
_state = State.CLOSED;
}

break;
}
break;
Expand Down Expand Up @@ -1351,7 +1365,7 @@ public void recycle()
{
_state = State.OPEN;
_apiState = ApiState.BLOCKING;
_softClose = false;
_softClose = true; // Stay closed until next request
_interceptor = _channel;
HttpConfiguration config = _channel.getHttpConfiguration();
_bufferSize = config.getOutputBufferSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,11 @@ public boolean isUserInRole(String role)
*/
public void setMetaData(MetaData.Request request)
{
if (_metaData == null && _input != null && _channel != null)
{
_input.recycle();
_channel.getResponse().getHttpOutput().reopen();
}
_metaData = request;
_method = request.getMethod();
_httpFields = request.getFields();
Expand Down Expand Up @@ -1771,7 +1776,7 @@ protected void recycle()

getHttpChannelState().recycle();
_requestAttributeListeners.clear();
_input.recycle();
// Defer _input.recycle() until setMetaData on next request, TODO replace with recycle and reopen in 10
_metaData = null;
_httpFields = null;
_trailers = null;
Expand Down

0 comments on commit 9611a25

Please sign in to comment.