From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jun Hao Newsgroups: gmane.emacs.bugs Subject: bug#23982: [master] Treat errno EINPROGRESS and ENOTCONN as EAGAIN for async connection Date: Thu, 14 Jul 2016 22:17:13 +0800 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1468509486 5693 80.91.229.3 (14 Jul 2016 15:18:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 14 Jul 2016 15:18:06 +0000 (UTC) To: 23982@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 14 17:17:53 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bNiOU-0007nj-S0 for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Jul 2016 17:17:43 +0200 Original-Received: from localhost ([::1]:54738 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNiOT-0008Ho-Dy for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Jul 2016 11:17:41 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNhSo-0002Wd-MJ for bug-gnu-emacs@gnu.org; Thu, 14 Jul 2016 10:18:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNhSk-0000hi-Bu for bug-gnu-emacs@gnu.org; Thu, 14 Jul 2016 10:18:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39185) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNhSk-0000hd-8U for bug-gnu-emacs@gnu.org; Thu, 14 Jul 2016 10:18:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bNhSk-0001w0-3v for bug-gnu-emacs@gnu.org; Thu, 14 Jul 2016 10:18:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jun Hao Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 14 Jul 2016 14:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 23982 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.14685058617391 (code B ref -1); Thu, 14 Jul 2016 14:18:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 14 Jul 2016 14:17:41 +0000 Original-Received: from localhost ([127.0.0.1]:51522 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bNhSO-0001v9-TE for submit@debbugs.gnu.org; Thu, 14 Jul 2016 10:17:41 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:45545) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bNhSL-0001us-Nv for submit@debbugs.gnu.org; Thu, 14 Jul 2016 10:17:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNhSF-0000dV-Kv for submit@debbugs.gnu.org; Thu, 14 Jul 2016 10:17:32 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:53351) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNhSF-0000dP-Hk for submit@debbugs.gnu.org; Thu, 14 Jul 2016 10:17:31 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNhSC-0001tU-Vk for bug-gnu-emacs@gnu.org; Thu, 14 Jul 2016 10:17:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNhS7-0000cO-Jd for bug-gnu-emacs@gnu.org; Thu, 14 Jul 2016 10:17:27 -0400 Original-Received: from omr-a017e.mx.aol.com ([204.29.186.68]:51939) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNhS7-0000cE-Ee for bug-gnu-emacs@gnu.org; Thu, 14 Jul 2016 10:17:23 -0400 Original-Received: from mtaout-aan02.mx.aol.com (mtaout-aan02.mx.aol.com [172.27.19.78]) by omr-a017e.mx.aol.com (Outbound Mail Relay) with ESMTP id 5422138000B9 for ; Thu, 14 Jul 2016 10:17:22 -0400 (EDT) Original-Received: from bogon (unknown [61.51.195.178]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mtaout-aan02.mx.aol.com (MUA/Third Party Client Interface) with ESMTPSA id DCB4238000092 for ; Thu, 14 Jul 2016 10:17:19 -0400 (EDT) User-agent: mu4e 0.9.17; emacs 25.1.50.2 x-aol-global-disposition: G X-AOL-VSS-INFO: 5800.7501/110832 X-AOL-VSS-CODE: clean DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mx.aol.com; s=20150623; t=1468505842; bh=46HS8I9JIlQpjVWgTE9eZjHJGPN4iuSAyYB8Ckcidcg=; h=From:To:Subject:Message-ID:Date:MIME-Version:Content-Type; b=WQSbB4OOSxiOR3kAa6OrQCf9094X/o7M7zz7lRqjCvqcZ5fRN6cQb0O6gOWY0jq+/ eO2RzlfpQsA14d2tuj4ZErT3GHF5PLCqpQrl0O8VFAqlbrg7EeZ+vNKwO3tbHsQSGr O6IrfB+rfdrxPNqtGdYL4909qm5Kq1UvYY14zJPI= x-aol-sid: 3039ac1b134e57879eef5c8a X-AOL-IP: 61.51.195.178 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:121068 Archived-At: --=-=-= Content-Type: text/plain Hi, For latest master branch, when try to use gnutls with async connection, the handshake will return fatal error if socket is in ENOTCONN or EINPROGRESS since gnutls treat these errors as fatal during push/pull and gives up. The later retry will fail because gnutls will mark the session invalid. This patch is asking gnutls to treat them as EAGAIN which is non-fatal. I only tested with OSX. Please see if you can reproduce it on Windows or Linux and if this patch works for them too. To reproduce run: emacs -Q --eval "(erc-tls :server \"irc.freenode.net\" :port 6697 :nick \"test\")" Current master branch will gave up connecting. -- Thanks - Jun --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Treat-errno-EINPROGRESS-and-ENOTCONN-as-EAGAIN-for-a.patch >From 8c69cab078d4c51d5c8f76f2aacb7bb8dd46dd7f Mon Sep 17 00:00:00 2001 From: Jun Hao Date: Thu, 14 Jul 2016 21:47:24 +0800 Subject: [PATCH] Treat errno EINPROGRESS and ENOTCONN as EAGAIN for async connection * src/gnutls.c: (emacs_gnutls_non_blocking_errno): treat errno EINPROGRESS and ENOTCONN as EAGAIN (emacs_gnutls_handshake): set errno function to it when async connection (Fgnutls_boot): set state with GNUTLS_NONBLOCK flag when async connection --- src/gnutls.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/gnutls.c b/src/gnutls.c index 7f05ac4..449a971 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -35,6 +35,10 @@ along with GNU Emacs. If not, see . */ static bool emacs_gnutls_handle_error (gnutls_session_t, int); +#ifndef WINDOWSNT +static int emacs_gnutls_non_blocking_errno(gnutls_transport_ptr_t ptr); +#endif + static bool gnutls_global_initialized; static void gnutls_log_function (int, const char *); @@ -383,6 +387,21 @@ gnutls_log_function2 (int level, const char *string, const char *extra) message ("gnutls.c: [%d] %s %s", level, string, extra); } +#ifndef WINDOWSNT +static int +emacs_gnutls_non_blocking_errno(gnutls_transport_ptr_t ptr) +{ + switch (errno) + { + case EINPROGRESS: + case ENOTCONN: + return EAGAIN; + default: + return errno; + } +} +#endif + int gnutls_try_handshake (struct Lisp_Process *proc) { @@ -460,6 +479,11 @@ emacs_gnutls_handshake (struct Lisp_Process *proc) gnutls_transport_set_ptr2 (state, (void *) (intptr_t) proc->infd, (void *) (intptr_t) proc->outfd); + if (proc->is_non_blocking_client) + /* for non blocking connection + treat EINPROGRESS and ENOTCONN as EAGAIN */ + gnutls_transport_set_errno_function(state, + emacs_gnutls_non_blocking_errno); #endif proc->gnutls_initstage = GNUTLS_STAGE_TRANSPORT_POINTERS_SET; @@ -1596,8 +1620,16 @@ one trustfile (usually a CA bundle). */) /* Call gnutls_init here: */ - GNUTLS_LOG (1, max_log_level, "gnutls_init"); - ret = gnutls_init (&state, GNUTLS_CLIENT); + if (XPROCESS (proc)->is_non_blocking_client) + { + GNUTLS_LOG (1, max_log_level, "gnutls_init with nonblocking"); + ret = gnutls_init(&state, GNUTLS_CLIENT|GNUTLS_NONBLOCK); + } + else + { + GNUTLS_LOG (1, max_log_level, "gnutls_init"); + ret = gnutls_init (&state, GNUTLS_CLIENT); + } XPROCESS (proc)->gnutls_state = state; if (ret < GNUTLS_E_SUCCESS) return gnutls_make_error (ret); -- 2.8.0 --=-=-=--