Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #7515 backport to 9.4 - Fix for connection limit problem #12363

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.ClosedSelectorException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
Expand Down Expand Up @@ -861,8 +862,8 @@ class Accept implements SelectorUpdate, Runnable, Closeable
public void close()
{
if (LOG.isDebugEnabled())
LOG.debug("closed accept of {}", channel);
IO.close(channel);
LOG.debug("Closed accept of {}", channel);
failed(new ClosedChannelException());
}

@Override
Expand All @@ -875,10 +876,9 @@ public void update(Selector selector)
}
catch (Throwable x)
{
IO.close(channel);
_selectorManager.onAcceptFailed(channel, x);
if (LOG.isDebugEnabled())
LOG.debug(x);
LOG.debug("Could not register channel after accept {}", channel, x);
failed(x);
}
}

Expand All @@ -887,23 +887,20 @@ public void run()
{
try
{
createEndPoint(channel, key);
_selectorManager.onAccepted(channel);
createEndPoint(channel, key);
}
catch (Throwable x)
{
if (LOG.isDebugEnabled())
LOG.debug(x);
LOG.debug("Could not process accepted channel {}", channel, x);
failed(x);
}
}

protected void failed(Throwable failure)
private void failed(Throwable failure)
{
IO.close(channel);
LOG.warn(String.valueOf(failure));
if (LOG.isDebugEnabled())
LOG.debug(failure);
_selectorManager.onAcceptFailed(channel, failure);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.jetty.io.Connection.Listener;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.SelectorManager;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.Name;
Expand Down Expand Up @@ -172,16 +173,18 @@ protected void doStop() throws Exception
}
}

protected void check()
protected boolean check()
{
if ((_accepting.size() + _connections) >= _maxConnections)
int total = _accepting.size() + _connections;
if (total >= _maxConnections)
{
if (!_limiting)
{
_limiting = true;
LOG.info("Connection Limit({}) reached for {}", _maxConnections, _connectors);
limit();
}
return total > _maxConnections;
}
else
{
Expand All @@ -191,6 +194,7 @@ protected void check()
LOG.info("Connection Limit({}) cleared for {}", _maxConnections, _connectors);
unlimit();
}
return false;
}
}

Expand Down Expand Up @@ -234,7 +238,8 @@ public void onAccepting(SelectableChannel channel)
_accepting.add(channel);
if (LOG.isDebugEnabled())
LOG.debug("onAccepting ({}+{}) < {} {}", _accepting.size(), _connections, _maxConnections, channel);
check();
if (check())
IO.close(channel);
}
}

Expand Down