Skip to content

ConnectionLimit doesn't work with WebSocket connections. #13324

@ZadokhinDima

Description

@ZadokhinDima

Jetty version(s)

The issue is reproduced for Jetty 12.0.20. It was most likely introduced by change: https://github.com/jetty/jetty.project/pull/12320/files where Set of accepting connections was replaced by simple counter.

Jetty Environment

Any
Java version/vendor (use: java -version)
Any
OS type/version
Any
Description
org.eclipse.jetty.server.ConnectionLimit is created to limit active connections that Jetty server is handling. However, internal logic of this class doesn't work properly for web socket connections.
The problem is with _accepting counter: it is decremented for each onOpened call. In web socket case, onOpened called twice: for handshake and actual WS connection. So _accepting counter enters negative values and the behavior of limiter is broken. Logs:

14:25:16.140 [qtp1782580546-35-acceptor-0@3ca674fe-ServerConnector@740fb309{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}] DEBUG o.e.jetty.server.ConnectionLimit - Accepting (1+0) <= 5 java.nio.channels.SocketChannel[connected local=/[0:0:0:0:0:0:0:1]:8080 remote=/[0:0:0:0:0:0:0:1]:63507]
14:25:16.175 [qtp1782580546-36] DEBUG o.e.jetty.server.ConnectionLimit - Opened (0+1) <= 5 HttpConnection@4b126155::SocketChannelEndPoint@2c168a4[{l=/[0:0:0:0:0:0:0:1]:8080,r=/[0:0:0:0:0:0:0:1]:63507,OPEN,fill=-,flush=-,to=29/30000}{io=0/0,kio=0,kro=0}]->[HttpConnection@4b126155[p=HttpParser{s=START,0 of -1},g=HttpGenerator@2771ee38{s=START}]=>HttpChannelState@63c5b38f{handling=null, handled=false, send=SENDING, completed=false, request=null}]
14:25:16.222 [qtp1782580546-38] DEBUG o.e.jetty.server.ConnectionLimit - Closed (0+0) <= 5 HttpConnection@4b126155::SocketChannelEndPoint@2c168a4[{l=/[0:0:0:0:0:0:0:1]:8080,r=/[0:0:0:0:0:0:0:1]:63507,OPEN,fill=-,flush=-,to=1/30000}{io=0/0,kio=0,kro=1}]->[HttpConnection@4b126155[p=HttpParser{s=END,0 of -1},g=HttpGenerator@2771ee38{s=END}]=>HttpChannelState@63c5b38f{handling=null, handled=true, send=LAST_COMPLETE, completed=true, request=GET@2a4a534a http://localhost:8080/echo HTTP/1.1}]
14:25:16.222 [qtp1782580546-38] DEBUG o.e.jetty.server.ConnectionLimit - Opened (-1+1) <= 5 WebSocketConnection@3c760760::SocketChannelEndPoint@2c168a4[{l=/[0:0:0:0:0:0:0:1]:8080,r=/[0:0:0:0:0:0:0:1]:63507,OPEN,fill=-,flush=-,to=2/30000}{io=0/0,kio=0,kro=1}]->[WebSocketConnection@3c760760[SERVER,p=Parser@199c38ac[s=START,c=0,o=0x0,m=-,l=0],f=Flusher@6958aafa[IDLE][queueSize=0,aggregate=null],g=org.eclipse.jetty.websocket.core.internal.Generator@11706498]]
14:26:16.279 [qtp1782580546-21] DEBUG o.e.jetty.server.ConnectionLimit - Closed (-1+0) <= 5 WebSocketConnection@3c760760::SocketChannelEndPoint@2c168a4[{l=null,r=null,CLOSED,fill=-,flush=-,to=2/30000}{io=0/0,kio=-1,kro=-1}]->[WebSocketConnection@3c760760[SERVER,p=Parser@199c38ac[s=START,c=0,o=0x0,m=-,l=0],f=Flusher@6958aafa[FAILED][queueSize=0,aggregate=null],g=org.eclipse.jetty.websocket.core.internal.Generator@11706498]]

How to reproduce?
Demo repo
Run application with main class org.example.websocketdemo.EchoServer. It has connection limit configured to 5.
Run python script in root folder. It will successfully open 20 connections.

Metadata

Metadata

Labels

BugFor general bugs on Jetty side

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions