Skip to content

Commit

Permalink
Fixes #4904 - WebsocketClient creates more connections than needed.
Browse files Browse the repository at this point in the history
After merge fixes.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Jun 1, 2020
1 parent 44d601a commit 4277759
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,30 @@ public abstract class AbstractConnectionPool implements ConnectionPool, Dumpable
private final int maxConnections;
private final Callback requester;

/**
* @param destination the correspondent destination
* @param maxConnections the max number of connections
* @param requester the callback to notify about new connection creation/failure
* @deprecated use {@link #AbstractConnectionPool(HttpDestination, int, Callback)} instead
*/
@Deprecated
protected AbstractConnectionPool(Destination destination, int maxConnections, Callback requester)
{
this.destination = (HttpDestination)destination;
this((HttpDestination)destination, maxConnections, requester);
}

protected AbstractConnectionPool(HttpDestination destination, int maxConnections, Callback requester)
{
this.destination = destination;
this.maxConnections = maxConnections;
this.requester = requester;
}

protected HttpDestination getHttpDestination()
{
return destination;
}

@ManagedAttribute(value = "The max number of connections", readonly = true)
public int getMaxConnectionCount()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class DuplexConnectionPool extends AbstractConnectionPool implements Swee

public DuplexConnectionPool(Destination destination, int maxConnections, Callback requester)
{
super(destination, maxConnections, requester);
super((HttpDestination)destination, maxConnections, requester);
this.idleConnections = new ArrayDeque<>(maxConnections);
this.activeConnections = new HashSet<>(maxConnections);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private void process(boolean create)
}
}

public ProcessResult process(Connection connection)
private ProcessResult process(Connection connection)
{
HttpClient client = getHttpClient();
HttpExchange exchange = getHttpExchanges().poll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class MultiplexConnectionPool extends AbstractConnectionPool implements C
private static final Logger LOG = Log.getLogger(MultiplexConnectionPool.class);

private final ReentrantLock lock = new ReentrantLock();
private final HttpDestination destination;
private final Deque<Holder> idleConnections;
private final Map<Connection, Holder> muxedConnections;
private final Map<Connection, Holder> busyConnections;
Expand All @@ -51,7 +50,6 @@ public class MultiplexConnectionPool extends AbstractConnectionPool implements C
public MultiplexConnectionPool(HttpDestination destination, int maxConnections, Callback requester, int maxMultiplex)
{
super(destination, maxConnections, requester);
this.destination = destination;
this.idleConnections = new ArrayDeque<>(maxConnections);
this.muxedConnections = new HashMap<>(maxConnections);
this.busyConnections = new HashMap<>(maxConnections);
Expand All @@ -64,7 +62,7 @@ public Connection acquire()
Connection connection = activate();
if (connection == null)
{
int queuedRequests = destination.getQueuedRequestCount();
int queuedRequests = getHttpDestination().getQueuedRequestCount();
int maxMultiplex = getMaxMultiplex();
int maxPending = ceilDiv(queuedRequests, maxMultiplex);
tryCreate(maxPending);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public RoundRobinConnectionPool(Destination destination, int maxConnections, Cal

public RoundRobinConnectionPool(Destination destination, int maxConnections, Callback requester, int maxMultiplex)
{
super(destination, maxConnections, requester);
super((HttpDestination)destination, maxConnections, requester);
entries = new ArrayList<>(maxConnections);
for (int i = 0; i < maxConnections; ++i)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.eclipse.jetty.client.http;

import java.lang.reflect.Method;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
Expand All @@ -28,6 +29,7 @@
import org.eclipse.jetty.client.DuplexConnectionPool;
import org.eclipse.jetty.client.EmptyServerHandler;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpDestination;
import org.eclipse.jetty.client.Origin;
import org.eclipse.jetty.client.api.Connection;
import org.eclipse.jetty.client.api.ContentResponse;
Expand Down Expand Up @@ -205,7 +207,9 @@ public void testAcquireProcessReleaseAcquireReturnsSameConnection(Scenario scena
}

// There are no exchanges so process() is a no-op.
destination.process(connection1);
Method process = HttpDestination.class.getDeclaredMethod("process", Connection.class);
process.setAccessible(true);
process.invoke(destination, connection1);
destination.release(connection1);

Connection connection2 = connectionPool.acquire();
Expand Down

0 comments on commit 4277759

Please sign in to comment.