Skip to content

Commit

Permalink
UNDERTOW-840 Proxy still attempts to assign connections to requests t…
Browse files Browse the repository at this point in the history
…hat have timed out
  • Loading branch information
stuartwdouglas committed Sep 19, 2016
1 parent 1891e93 commit d0830ea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/io/undertow/UndertowLogger.java
Expand Up @@ -379,4 +379,8 @@ void nodeConfigCreated(URI connectionURI, String balancer, String domain, String
@LogMessage(level = ERROR)
@Message(id = 5080, value = "HttpServerExchange cannot have both async IO resumed and dispatch() called in the same cycle")
void resumedAndDispatched();

@LogMessage(level = ERROR)
@Message(id = 5081, value = "Response has already been started, cannot proxy request %s")
void cannotProxyStartedRequest(HttpServerExchange exchange);
}
Expand Up @@ -312,16 +312,21 @@ private void redistributeQueued(HostThreadData hostData) {
}

private void connectionReady(final ConnectionHolder result, final ProxyCallback<ProxyConnection> callback, final HttpServerExchange exchange, final boolean exclusive) {
exchange.addExchangeCompleteListener(new ExchangeCompletionListener() {
@Override
public void exchangeEvent(HttpServerExchange exchange, NextListener nextListener) {
if (!exclusive) {
returnConnection(result);
try {
exchange.addExchangeCompleteListener(new ExchangeCompletionListener() {
@Override
public void exchangeEvent(HttpServerExchange exchange, NextListener nextListener) {
if (!exclusive) {
returnConnection(result);
}
nextListener.proceed();
}
nextListener.proceed();
}
});

});
} catch (Exception e) {
returnConnection(result);
callback.failed(exchange);
return;
}
callback.completed(exchange, new ProxyConnection(result.clientConnection, uri.getPath() == null ? "/" : uri.getPath()));
}

Expand Down Expand Up @@ -592,7 +597,7 @@ private XnioExecutor.Key getTimeoutKey() {
}

private boolean isCancelled() {
return cancelled;
return cancelled || exchange.isResponseStarted();
}

private void setTimeoutKey(XnioExecutor.Key timeoutKey) {
Expand Down
Expand Up @@ -165,6 +165,13 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
next.handleRequest(exchange);
return;
}
if(exchange.isResponseStarted()) {
//we can't proxy a request that has already started, this is basically a server configuration error
UndertowLogger.REQUEST_LOGGER.cannotProxyStartedRequest(exchange);
exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR);
exchange.endExchange();
return;
}
final long timeout = maxRequestTime > 0 ? System.currentTimeMillis() + maxRequestTime : 0;
final ProxyClientHandler clientHandler = new ProxyClientHandler(exchange, target, timeout, maxConnectionRetries, idempotentRequestPredicate);
if (timeout > 0) {
Expand Down

0 comments on commit d0830ea

Please sign in to comment.