427512 - ReadPendingException in case of HTTP Proxy tunnelling.

Fixed by marking the old HttpConnection as "soft closed", that is
make it so that isClosed() returns true but the underlying EndPoint
is not closed.
This allows the HttpReceiver to skip the registration for fill
interest, so that the ReadPendingException is not thrown.
This commit is contained in:
Simone Bordet 2014-02-05 21:30:06 +01:00
parent 7725056234
commit f147362915
2 changed files with 11 additions and 2 deletions

View File

@ -27,6 +27,7 @@ import org.eclipse.jetty.client.api.Connection;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.client.http.HttpConnectionOverHTTP;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpScheme;
@ -179,9 +180,12 @@ public class HttpProxy extends ProxyConfiguration.Proxy
HttpDestination destination = (HttpDestination)context.get(HttpClientTransport.HTTP_DESTINATION_CONTEXT_KEY);
HttpClient client = destination.getHttpClient();
ClientConnectionFactory sslConnectionFactory = new SslClientConnectionFactory(client.getSslContextFactory(), client.getByteBufferPool(), client.getExecutor(), connectionFactory);
org.eclipse.jetty.io.Connection oldConnection = endPoint.getConnection();
HttpConnectionOverHTTP oldConnection = (HttpConnectionOverHTTP)endPoint.getConnection();
org.eclipse.jetty.io.Connection newConnection = sslConnectionFactory.newConnection(endPoint, context);
Helper.replaceConnection(oldConnection, newConnection);
// Avoid setting fill interest in the old Connection,
// without closing the underlying EndPoint.
oldConnection.softClose();
LOG.debug("HTTP tunnel established: {} over {}", oldConnection, newConnection);
}
catch (Throwable x)

View File

@ -120,7 +120,7 @@ public class HttpConnectionOverHTTP extends AbstractConnection implements Connec
@Override
public void close()
{
if (closed.compareAndSet(false, true))
if (softClose())
{
getHttpDestination().close(this);
getEndPoint().shutdownOutput();
@ -130,6 +130,11 @@ public class HttpConnectionOverHTTP extends AbstractConnection implements Connec
}
}
public boolean softClose()
{
return closed.compareAndSet(false, true);
}
@Override
public String toString()
{