Skip to content

Commit

Permalink
Added/improved many log messages to trace sockets usage and fixed two…
Browse files Browse the repository at this point in the history
… socket leaks
  • Loading branch information
glpatcern committed Mar 31, 2016
1 parent 1211fd1 commit 843ba58
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions rpyc/utils/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def accept(self):
return

sock.setblocking(True)
self.logger.info("accepted %s:%s", addrinfo[0], addrinfo[1])
self.logger.info("accepted %s:%s with fd %d", addrinfo[0], addrinfo[1], sock.fileno())
self.clients.add(sock)
self._accept_method(sock)

Expand Down Expand Up @@ -356,6 +356,7 @@ def _drop_connection(self, fd):
# the active connection has already been removed
pass
# close connection
self.logger.info("Closing connection for fd %d", fd)
conn.close()

def _add_inactive_connection(self, fd):
Expand Down Expand Up @@ -392,7 +393,7 @@ def _poll_inactive_clients(self):
except Exception:
ex = sys.exc_info()[1]
# "Caught exception in Worker thread" message
self.logger.warning("failed to poll clients, caught exception : %s", str(ex))
self.logger.warning("Failed to poll clients, caught exception : %s", str(ex))
# wait a bit so that we do not loop too fast in case of error
time.sleep(0.2)

Expand Down Expand Up @@ -436,7 +437,7 @@ def _serve_clients(self):
except Exception:
ex = sys.exc_info()[1]
# "Caught exception in Worker thread" message
self.logger.warning("failed to serve client, caught exception : %s", str(ex))
self.logger.warning("Failed to serve client, caught exception : %s", str(ex))
# wait a bit so that we do not loop too fast in case of error
time.sleep(0.2)

Expand All @@ -450,7 +451,7 @@ def _authenticate_and_build_connection(self, sock):
try:
sock, credentials = self.authenticator(sock)
except AuthenticationError:
self.logger.info("%s:%s failed to authenticate, rejecting connection", h, p)
self.logger.warning("%s:%s failed to authenticate, rejecting connection", h, p)
return None
else:
credentials = None
Expand All @@ -467,13 +468,20 @@ def _accept_method(self, sock):
conn = self._authenticate_and_build_connection(sock)
# put the connection in the active queue
if conn:
h, p = sock.getpeername()
fd = conn.fileno()
self.logger.debug("Created connection to %s:%d with fd %d", h, p, fd)
self.fd_to_conn[fd] = conn
self._add_inactive_connection(fd)
self.clients.clear()
else:
self.logger.warning("Failed to authenticate and build connection, closing %s:%d", h, p)
sock.close()
except Exception:
h, p = sock.getpeername()
ex = sys.exc_info()[1]
self.logger.warning("failed to serve client, caught exception : %s", str(ex))
self.logger.warning("Failed to serve client for %s:%d, caught exception : %s", h, p, str(ex))
sock.close()


class ForkingServer(Server):
Expand Down

0 comments on commit 843ba58

Please sign in to comment.