From patchwork Wed Jun 4 21:02:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weston Andros Adamson X-Patchwork-Id: 4296981 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 17E3FBEEA7 for ; Wed, 4 Jun 2014 21:03:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3B17D2012E for ; Wed, 4 Jun 2014 21:03:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A199720251 for ; Wed, 4 Jun 2014 21:02:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752092AbaFDVCq (ORCPT ); Wed, 4 Jun 2014 17:02:46 -0400 Received: from mail-ig0-f175.google.com ([209.85.213.175]:48795 "EHLO mail-ig0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752086AbaFDVCp (ORCPT ); Wed, 4 Jun 2014 17:02:45 -0400 Received: by mail-ig0-f175.google.com with SMTP id uq10so6798277igb.8 for ; Wed, 04 Jun 2014 14:02:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TU41baPVj35XAO0h3HmnYfDUhHDYbZk9kTygGxZbFK4=; b=dUMUn0awzJGsjmaFWbvKjSoUNIIJmAuyqbTDPqOvEpJOZFFlrxI1P50nIc80DjjbLn rX7GOrd2VZjQ+3ZZrpecFJj/OOCu7ibM+vB/sOO3SM8Ock7K/FN3Spi6tmPJIxle0g5A xjpdB9L7b0gzJZDcV5GkuHjgRLxRLmWfUbJNT/GGvOTeNkKu9TQqLABqw+26qsViMIBP 4GxpcPF3b7OANnJdSapVe5+b060GFkm+N3JCgpkacOb/igQYsrGe23Q4x5bj6Dj+y9fF Cd7KhJiypr1NwFmHQBeLf5iVIh/FMP6XFMnhJWw9iWPNWzJfVuDEQreyVp06irwEbBGv sDvQ== X-Gm-Message-State: ALoCoQk+BtenXz4pgyVxF7IwSk4PRt0Su35/99jKPDxV/weDpOI70aZm26F14gc+lbqE4G34uB26 X-Received: by 10.50.114.34 with SMTP id jd2mr11329968igb.35.1401915764737; Wed, 04 Jun 2014 14:02:44 -0700 (PDT) Received: from gavrio-wifi.robotsandstuff.fake (c-98-209-19-144.hsd1.mi.comcast.net. [98.209.19.144]) by mx.google.com with ESMTPSA id qh3sm47684584igb.17.2014.06.04.14.02.43 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 04 Jun 2014 14:02:44 -0700 (PDT) From: Weston Andros Adamson To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, Weston Andros Adamson Subject: [PATCH pynfs 16/17] rpc: on socket error, close and mark pipe inactive Date: Wed, 4 Jun 2014 17:02:05 -0400 Message-Id: <1401915726-29092-18-git-send-email-dros@primarydata.com> X-Mailer: git-send-email 1.8.5.2 (Apple Git-48) In-Reply-To: <1401915726-29092-1-git-send-email-dros@primarydata.com> References: <1401915726-29092-1-git-send-email-dros@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP call _event_close() on socket errors instead of tracing back and mark the pipe as inactive so callers can reconnect as needed. Signed-off-by: Weston Andros Adamson --- rpc/rpc.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/rpc/rpc.py b/rpc/rpc.py index 250e945..4801883 100644 --- a/rpc/rpc.py +++ b/rpc/rpc.py @@ -351,6 +351,7 @@ class RpcPipe(Pipe): self._pending = {} # {xid:defer} self._lock = threading.Lock() # Protects fields below self._xid = 0 + self.set_active() def _get_xid(self): with self._lock: @@ -358,6 +359,15 @@ class RpcPipe(Pipe): self._xid = inc_u32(out) return out + def set_active(self): + self._active = True + + def clear_active(self): + self._active = False + + def is_active(self): + return self._active + def listen(self, xid, timeout=None): """Wait for a reply to a CALL.""" self._pending[xid].wait(timeout) @@ -500,15 +510,24 @@ class ConnectionHandler(object): log_p.warn(1, "polling error from %i" % fd) # STUB - now what? for fd in w: - self._event_write(fd) + try: + self._event_write(fd) + except socket.error, e: + self._event_close(fd) for fd in r: if fd in self.listeners: - self._event_connect_incoming(fd) + try: + self._event_connect_incoming(fd) + except socket.error, e: + self._event_close(fd) elif fd == self._alarm_poll.fileno(): commands = self._alarm_poll.recv(self.rsize) for c in commands: data = self._alarm.pop() - switch[c](data) + try: + switch[c](data) + except socket.error, e: + self._event_close(fd) else: try: data = self.sockets[fd].recv_records(self.rsize) @@ -557,6 +576,7 @@ class ConnectionHandler(object): self.writelist -= temp self.readlist -= temp self.errlist -= temp + self.sockets[fd].clear_active() self.sockets[fd].close() del self.sockets[fd]