Skip to content

Commit

Permalink
Bugfix for leak of num connections. Also fixed handling when max limi…
Browse files Browse the repository at this point in the history
…t = -1 (#9)
  • Loading branch information
Matt Hammond committed Aug 26, 2016
1 parent c84b5c9 commit 4c76042
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions dvbcss/protocol/server/__init__.py
Expand Up @@ -151,7 +151,7 @@ def __init__(self, maxConnectionsAllowed=-1, enabled=True):
Handler class for new connections. Should be provided as a configuration argument to cherrypy.
"""

self.connectionsRemaining = maxConnectionsAllowed
self.maxConnectionsAllowed = maxConnectionsAllowed
self._connections={} #: dict mapping WebSocket objects to connection data. Connection data is for use by subclasses to store data specific to each individual connection.
self.enabled = enabled

Expand Down Expand Up @@ -240,7 +240,6 @@ def _addConnection(self, webSock):
with self._lock:
self.log.debug("Adding websocket connection "+webSock.id())
if webSock not in self._connections:
self.connectionsRemaining -= 1
self._connections[webSock] = self.getDefaultConnectionData()
try:
self.onClientConnect(webSock)
Expand All @@ -258,7 +257,6 @@ def _removeConnection(self, webSock):
with self._lock:
self.log.debug("Removing websocket connection "+webSock.id())
if webSock in self._connections:
self.connectionsRemaining += 1
conn=self._connections[webSock]
del self._connections[webSock]
self.onClientDisconnect(webSock, conn)
Expand Down Expand Up @@ -305,7 +303,7 @@ def canAllocateConnection(cls):
:return: True only if the connection limit of the parent server has not yet been reached. Otherwise False.
"""
serverSelf.log.debug("Checking concurrent connection allocation")
return serverSelf.connectionsRemaining > 0
return serverSelf.maxConnectionsAllowed < 0 or serverSelf.maxConnectionsAllowed > len(serverSelf._connections)

def opened(self):
# cant process sensibly now because websocket upgrade is complete
Expand Down

0 comments on commit 4c76042

Please sign in to comment.