Skip to content

Commit

Permalink
Close CLOSE_WAIT sockets by default (#1104)
Browse files Browse the repository at this point in the history
* Add close_half_closed_sockets function

* Call close_half_closed_sockets in xmlrpcapi by default
  • Loading branch information
dirk-thomas authored Jul 21, 2017
1 parent fad9104 commit 2d987bc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tools/rosmaster/src/rosmaster/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
monkey_patch()
del monkey_patch

import socket

_proxies = {} #cache ServerProxys
def xmlrpcapi(uri):
"""
Expand All @@ -62,9 +64,19 @@ def xmlrpcapi(uri):
return None
if not uri in _proxies:
_proxies[uri] = ServerProxy(uri)
close_half_closed_sockets()
return _proxies[uri]


def close_half_closed_sockets():
for proxy in _proxies.values():
transport = proxy("transport")
if transport._connection and transport._connection[1] is not None and transport._connection[1].sock is not None:
state = transport._connection[1].sock.getsockopt(socket.SOL_TCP, socket.TCP_INFO)
if state == 8: # CLOSE_WAIT
transport.close()


def remove_server_proxy(uri):
if uri in _proxies:
del _proxies[uri]

0 comments on commit 2d987bc

Please sign in to comment.