Skip to content

Commit

Permalink
Backport of jetty#12320.
Browse files Browse the repository at this point in the history
Signed-off-by: Volodymyr Sorokin <[email protected]>
  • Loading branch information
vlsorokin committed Oct 13, 2024
1 parent befe30b commit ef1a16d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
18 changes: 8 additions & 10 deletions jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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 @@ -862,8 +863,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 @@ -876,10 +877,9 @@ public void update(Selector selector)
}
catch (Throwable x)
{
IO.close(channel);
_selectorManager.onAcceptFailed(channel, x);
if (LOG.isDebugEnabled())
LOG.debug("Could not register channel after accept {}", channel, x);
failed(x);
}
}

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

protected void failed(Throwable failure)
private void failed(Throwable failure)
{
IO.close(channel);
if (LOG.isDebugEnabled())
LOG.warn("Could not accept {}", channel, failure);
else
LOG.warn("Could not accept {}: {}", channel, String.valueOf(failure));
_selectorManager.onAcceptFailed(channel, failure);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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 @@ -169,16 +170,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 @@ -188,6 +191,7 @@ protected void check()
LOG.info("Connection Limit({}) cleared for {}", _maxConnections, _connectors);
unlimit();
}
return false;
}
}

Expand Down Expand Up @@ -231,7 +235,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

0 comments on commit ef1a16d

Please sign in to comment.