Skip to content

Commit

Permalink
Fix DoS socket/memory leak for not connected clients (#185)
Browse files Browse the repository at this point in the history
If a client disconnects sock.close() is currently never called because one cannot shutdown a not connected client:

Traceback (most recent call last):
  File "circuits/net/sockets.py", line 460, in _close
    sock.shutdown(2)
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 107] Transport endpoint is not connected

This leads to still opened file descriptors/sockets in the procees:
python  20195 spaceone   10u  sock      0,6      0t0 11410688 can't identify protocol

If the server component runs for a longer time somehwen the open file descriptor limits is reached and your server is not able to react to any connection anymore:
Errno 105: No buffer space available
  • Loading branch information
spaceone authored and prologic committed Nov 7, 2016
1 parent 3ec4b32 commit dd604e3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions circuits/net/sockets.py
Expand Up @@ -155,6 +155,9 @@ def _close(self):

try:
self._sock.shutdown(2)
except SocketError:
pass
try:
self._sock.close()
except SocketError:
pass
Expand Down Expand Up @@ -497,6 +500,9 @@ def _close(self, sock):

try:
sock.shutdown(2)
except SocketError:
pass
try:
sock.close()
except SocketError:
pass
Expand Down

0 comments on commit dd604e3

Please sign in to comment.