GNU bug report logs -
#23982
[master] Treat errno EINPROGRESS and ENOTCONN as EAGAIN for async connection
Previous Next
Reported by: Jun Hao <jun_hao <at> aol.com>
Date: Thu, 14 Jul 2016 14:18:01 UTC
Severity: normal
Tags: patch
Merged with 22929,
23225,
23503
Found in version 25.1.50
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Wed, 3 Aug 2016 02:02:11 -0700
with message-id <8e870d1c-d548-0e34-5a9b-961b1773706c <at> cs.ucla.edu>
and subject line Re: bug#23982: [master] Treat errno EINPROGRESS and ENOTCONN as EAGAIN for async connection
has caused the debbugs.gnu.org bug report #23982,
regarding [master] Treat errno EINPROGRESS and ENOTCONN as EAGAIN for async connection
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
23982: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23982
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
[Message part 3 (text/plain, inline)]
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
[0001-Treat-errno-EINPROGRESS-and-ENOTCONN-as-EAGAIN-for-a.patch (text/x-patch, inline)]
From 8c69cab078d4c51d5c8f76f2aacb7bb8dd46dd7f Mon Sep 17 00:00:00 2001
From: Jun Hao <jun_hao <at> aol.com>
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 <http://www.gnu.org/licenses/>. */
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
[Message part 5 (message/rfc822, inline)]
[Message part 6 (text/plain, inline)]
Eli Zaretskii wrote:
> I'm building Emacs with GnuTLS 3.3.11 since many moons ago.
OK, I installed the attached patches to GNU Emacs master. The first one requires
GnuTLS 2.12.2 or later. The second one uses the GNUTLS_NONBLOCK flag, and works
around the apparent GnuTLS bug with EINPROGRESS and ENOTCONN.
[0001-Require-GnuTLS-2.12.2-or-later.txt (text/plain, attachment)]
[0002-Fix-non-blocking-GnuTLS-with-slow-connection.txt (text/plain, attachment)]
This bug report was last modified 8 years and 283 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.