* Streaming: Fix active stream counting so it doesn't count streams

that are closed and in TIME-WAIT state. Also, break out of the
   counting loop as soon as we know the answer. (Ticket #1039)
This commit is contained in:
zzz
2013-09-24 12:40:35 +00:00
parent bd0c18b2e3
commit 61d5f46295

View File

@ -361,18 +361,29 @@ class ConnectionManager {
private boolean locked_tooManyStreams() { private boolean locked_tooManyStreams() {
int max = _defaultOptions.getMaxConns(); int max = _defaultOptions.getMaxConns();
if (max <= 0) return false; if (max <= 0) return false;
if (_connectionByInboundId.size() < max) return false; int size = _connectionByInboundId.size();
if (size < max) return false;
// count both so we can break out of the for loop asap
int active = 0; int active = 0;
int inactive = 0;
int maxInactive = size - max;
for (Connection con : _connectionByInboundId.values()) { for (Connection con : _connectionByInboundId.values()) {
if (con.getIsConnected()) // ticket #1039
active++; if (con.getIsConnected() &&
!(con.getCloseSentOn() > 0 && con.getCloseReceivedOn() > 0)) {
if (++active >= max)
return true;
} else {
if (++inactive > maxInactive)
return false;
}
} }
if ( (_connectionByInboundId.size() > 100) && (_log.shouldLog(Log.INFO)) ) //if ( (_connectionByInboundId.size() > 100) && (_log.shouldLog(Log.INFO)) )
_log.info("More than 100 connections! " + active // _log.info("More than 100 connections! " + active
+ " total: " + _connectionByInboundId.size()); // + " total: " + _connectionByInboundId.size());
return (active >= max); return false;
} }
/** /**