Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -205,32 +205,38 @@ void returnToPool(HttpConnection conn, Deadline now, long keepAlive) {

// it's possible that cleanup may have been called.
HttpConnection toClose = null;
boolean stopping = false;
stateLock.lock();
try {
if (cleanup.isDone()) {
return;
} else if (stopped) {
conn.close();
return;
}
if (MAX_POOL_SIZE > 0 && expiryList.size() >= MAX_POOL_SIZE) {
toClose = expiryList.removeOldest();
if (toClose != null) removeFromPool(toClose);
}
if (conn instanceof PlainHttpConnection) {
putConnection(conn, plainPool);
} else if (stopping = stopped) {
toClose = conn;
} else {
assert conn.isSecure();
putConnection(conn, sslPool);
if (MAX_POOL_SIZE > 0 && expiryList.size() >= MAX_POOL_SIZE) {
toClose = expiryList.removeOldest();
if (toClose != null) removeFromPool(toClose);
}
if (conn instanceof PlainHttpConnection) {
putConnection(conn, plainPool);
} else {
assert conn.isSecure();
putConnection(conn, sslPool);
}
expiryList.add(conn, now, keepAlive);
}
expiryList.add(conn, now, keepAlive);
} finally {
stateLock.unlock();
}
if (toClose != null) {
if (debug.on()) {
debug.log("Maximum pool size reached: removing oldest connection %s",
toClose.dbgString());
if (stopping) {
debug.log("Stopping: close connection %s",
toClose.dbgString());
} else {
debug.log("Maximum pool size reached: removing oldest connection %s",
toClose.dbgString());
}
}
close(toClose);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,13 @@ String getName() {

// Only called by the selector manager thread
private void shutdown() {
// first stop the client to avoid seeing exceptions
// about "selector manager closed"
Log.logTrace("{0}: stopping", owner.dbgTag);
try {
owner.stop();
} catch (Throwable ignored) {
}
try {
lock.lock();
try {
Expand All @@ -1345,6 +1352,7 @@ private void shutdown() {
}
} catch (IOException ignored) {
} finally {
// cleanup anything that might have been left behind
owner.stop();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,20 +311,20 @@ void close(Throwable cause) {
var connectTimerEvent = this.connectTimerEvent;
if (connectTimerEvent != null)
client().cancelTimer(connectTimerEvent);
if (Log.channel()) {
Log.logChannel("Closing channel: " + chan);
}
try {
tube.signalClosed(errorRef.get());
chan.close();
} finally {
client().connectionClosed(this);
}
} finally {
stateLock.unlock();
}
if (Log.channel()) {
Log.logChannel("Closing channel: " + chan);
}
try {
tube.signalClosed(errorRef.get());
chan.close();
} catch (IOException e) {
debug.log("Closing resulted in " + e);
Log.logTrace("Closing resulted in " + e);
} finally {
stateLock.unlock();
client().connectionClosed(this);
}
}

Expand Down