RFR: 8300268 : ServerImpl allows too many idle connections when using sun.net.httpserver.maxIdleConnections

Alan Bateman alanb at openjdk.org
Sat Feb 4 07:31:52 UTC 2023


On Fri, 3 Feb 2023 17:58:28 GMT, Darragh Clarke <duke at openjdk.org> wrote:

> Currently there is a race condition that can allow for too many 'idleConnections' in `ServerImpl`
> 
> This PR adds a lock to make sure only one connection can be marked Idle at a time as well as a test that consistently failed before the change but which now passes.

src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java line 969:

> 967: 
> 968:         idleConnectionLock.lock();
> 969:         if (idleConnections.size() >= MAX_IDLE_CONNECTIONS) {

Just a general point here is that you probably should use try-finally and do the unlock in the finally block, just in case something between lock and unlock throws or the control flow is changed for some reason, like an early return.

-------------

PR: https://git.openjdk.org/jdk/pull/12413


More information about the net-dev mailing list