Skip to content

Commit

Permalink
Merge pull request #191 from glpatcern/master
Browse files Browse the repository at this point in the history
Further fixes unveiled after fix for bug #182
  • Loading branch information
coldfix authored May 29, 2017
2 parents 0f82f11 + 12544f4 commit 057b3d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 4 additions & 1 deletion rpyc/lib/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def register(self, fd, mode):
if "e" in mode:
flags |= select_module.POLLERR
if "h" in mode:
# POLLRDHUP is a linux only extension, not know to python, but nevertheless
# POLLRDHUP is a linux only extension, not known to python, but nevertheless
# used and thus needed in the flags
POLLRDHUP = 0x2000
flags |= select_module.POLLHUP | select_module.POLLNVAL | POLLRDHUP
Expand All @@ -101,6 +101,9 @@ def register(self, fd, mode):
def unregister(self, fd):
self._poll.unregister(fd)
def poll(self, timeout = None):
if timeout:
# the real poll takes milliseconds while we have seconds here
timeout = 1000*timeout
events = self._poll.poll(timeout)
processed = []
for fd, evt in events:
Expand Down
22 changes: 15 additions & 7 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 @@ -360,6 +360,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 @@ -388,15 +389,15 @@ def _poll_inactive_clients(self):
Check whether inactive clients have become active'''
while self.active:
try:
# the actual poll, with a timeout of 1s so that we can exit in case
# the actual poll, with a timeout of 0.1s so that we can exit in case
# we re not active anymore
active_clients = self.poll_object.poll(1)
active_clients = self.poll_object.poll(0.1)
# for each client that became active, put them in the active queue
self._handle_poll_result(active_clients)
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 @@ -440,7 +441,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 @@ -454,7 +455,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 @@ -471,13 +472,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 057b3d1

Please sign in to comment.