Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further fixes unveiled after fix for bug #182 #191

Merged
merged 2 commits into from May 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion rpyc/lib/compat.py
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
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 @@ -384,15 +385,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 @@ -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