From patchwork Fri Jun 11 14:29:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Terry Wilson X-Patchwork-Id: 1490982 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FamKbMva; dkim-atps=neutral Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G1jt15TLTz9sWQ for ; Sat, 12 Jun 2021 00:30:01 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 0B01C41575; Fri, 11 Jun 2021 14:29:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6Xte5AmAUYVR; Fri, 11 Jun 2021 14:29:57 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id C7F0A4055F; Fri, 11 Jun 2021 14:29:56 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9AD8FC000D; Fri, 11 Jun 2021 14:29:56 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id DA0E1C000B for ; Fri, 11 Jun 2021 14:29:55 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id B541A83E16 for ; Fri, 11 Jun 2021 14:29:55 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AIAlxQWvGCKJ for ; Fri, 11 Jun 2021 14:29:55 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id DFF5E83DFE for ; Fri, 11 Jun 2021 14:29:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623421793; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6M7UgT5i2r8ZnrWSxdmcE6t3spzzFpC8YpRHH9eWMrQ=; b=FamKbMvaLyRFGH0Lnxzh+nR171sVcGz8gU3kQ5j1SS+BXP6CF8pgJrvyFdg1QvACiX5bLt +KJMGEBcZ2HHTF8pdHDyPbEXuYlHsglkCgDuZT2XdBwiiDuYLxRjb5/2igfHRYaWyL9sLw o0wd0gkquFvtGlNGXKDbMVlkzvHaPlI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-64-EUK62yUfNWqUzJ6VSrjSZQ-1; Fri, 11 Jun 2021 10:29:52 -0400 X-MC-Unique: EUK62yUfNWqUzJ6VSrjSZQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C00148042A8 for ; Fri, 11 Jun 2021 14:29:51 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-118-9.rdu2.redhat.com [10.10.118.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66DAB5D9CC; Fri, 11 Jun 2021 14:29:51 +0000 (UTC) From: Terry Wilson To: dev@openvswitch.org Date: Fri, 11 Jun 2021 09:29:23 -0500 Message-Id: <20210611142923.474384-1-twilson@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=twilson@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3] [python] Don't mix system poll/monkeypatched select X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This is a partial revert of c1aa16d19, but keeps its test. Applications that use eventlet cannot use poll() without blocking. To fix an issue where the check_connection_completion() code would not detect connection errors when using select(), we switched to using the system poll() for checking the connection while leaving the select-based poller the default. This mixes monkeypatched and unpatched code and caused eventlet-based code to block every time we connect. According to the connect(2) man page, you can detect connect() errors when using select(): After select(2) indicates writability, use getsockopt(2) to read the SO_ERROR option at level SOL_SOCKET to determine whether connect() completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual error codes listed here, explaining the reason for the failure) so this patch does that instead. Signed-off-by: Terry Wilson Acked-by: Numan Siddique --- python/ovs/poller.py | 35 ++--------------------------------- python/ovs/socket_util.py | 9 ++++++--- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/python/ovs/poller.py b/python/ovs/poller.py index 3624ec865..7b3238d6d 100644 --- a/python/ovs/poller.py +++ b/python/ovs/poller.py @@ -31,22 +31,14 @@ except ImportError: SSL = None try: - from eventlet import patcher as eventlet_patcher + import eventlet.patcher def _using_eventlet_green_select(): - return eventlet_patcher.is_monkey_patched(select) + return eventlet.patcher.is_monkey_patched(select) except: - eventlet_patcher = None - def _using_eventlet_green_select(): return False -try: - from gevent import monkey as gevent_monkey -except: - gevent_monkey = None - - vlog = ovs.vlog.Vlog("poller") POLLIN = 0x001 @@ -265,26 +257,3 @@ class Poller(object): def __reset(self): self.poll = SelectPoll() self.timeout = -1 - - -def get_system_poll(): - """Returns the original select.poll() object. If select.poll is - monkey patched by eventlet or gevent library, it gets the original - select.poll and returns an object of it using the - eventlet.patcher.original/gevent.monkey.get_original functions. - - As a last resort, if there is any exception it returns the - SelectPoll() object. - """ - try: - if _using_eventlet_green_select(): - _system_poll = eventlet_patcher.original("select").poll - elif gevent_monkey and gevent_monkey.is_object_patched( - 'select', 'poll'): - _system_poll = gevent_monkey.get_original('select', 'poll') - else: - _system_poll = select.poll - except: - _system_poll = SelectPoll - - return _system_poll() diff --git a/python/ovs/socket_util.py b/python/ovs/socket_util.py index 3faa64e9d..7dd000916 100644 --- a/python/ovs/socket_util.py +++ b/python/ovs/socket_util.py @@ -159,8 +159,8 @@ def make_unix_socket(style, nonblock, bind_path, connect_path, short=False): def check_connection_completion(sock): + p = ovs.poller.SelectPoll() if sys.platform == "win32": - p = ovs.poller.SelectPoll() event = winutils.get_new_event(None, False, True, None) # Receive notification of readiness for writing, of completed # connection or multipoint join operation, and of socket closure. @@ -170,12 +170,15 @@ def check_connection_completion(sock): win32file.FD_CLOSE) p.register(event, ovs.poller.POLLOUT) else: - p = ovs.poller.get_system_poll() p.register(sock, ovs.poller.POLLOUT) pfds = p.poll(0) if len(pfds) == 1: revents = pfds[0][1] - if revents & ovs.poller.POLLERR or revents & ovs.poller.POLLHUP: + if revents & ovs.poller.POLLOUT: + # This is how select() indicates a connect() error + return sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) + elif revents & ovs.poller.POLLERR or revents & ovs.poller.POLLHUP: + # This is how poll() indicates a connect() error try: # The following should raise an exception. sock.send("\0".encode(), socket.MSG_DONTWAIT)