From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alain Schneble Newsgroups: gmane.emacs.bugs Subject: bug#22789: 25.1.50; In last master build https connections stop working Date: Fri, 4 Mar 2016 22:36:56 +0100 Message-ID: <86a8mekjrb.fsf@realize.ch> References: <864mcyo14y.fsf@Lenovo-PC.i-did-not-set--mail-host-address--so-tickle-me> <83k2lugeym.fsf@gnu.org> <871t81wtyt.fsf@gnus.org> <87r3g1veqc.fsf@gnus.org> <86si0euizj.fsf@realize.ch> <871t7xhj7t.fsf@gnus.org> <86oab1vjm9.fsf@realize.ch> <86d1rhpvcq.fsf@realize.ch> <834mctbitq.fsf@gnu.org> <868u25p3m2.fsf@realize.ch> <83io18ahya.fsf@gnu.org> <86y4a3on6f.fsf@realize.ch> <87oaazg7fv.fsf@gnus.org> <86twkro0vr.fsf@realize.ch> <83d1rf8ifj.fsf@gnu.org> <86povfnm9r.fsf@realize.ch> <8337sa9865.fsf@gnu.org> <86bn6ynrbw.fsf@realize.ch> <83vb566v5b.fsf@gnu.org> <83d1razkmq.fsf@gnu.org> <86egbqkwsb.fsf@realize.ch> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1457127565 7275 80.91.229.3 (4 Mar 2016 21:39:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 4 Mar 2016 21:39:25 +0000 (UTC) Cc: larsi@gnus.org, j_l_domenech@yahoo.com, 22789@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Mar 04 22:39:12 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 1abxRI-0003qZ-Cw for geb-bug-gnu-emacs@m.gmane.org; Fri, 04 Mar 2016 22:39:12 +0100 Original-Received: from localhost ([::1]:43602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abxRH-00039d-RD for geb-bug-gnu-emacs@m.gmane.org; Fri, 04 Mar 2016 16:39:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abxRC-00037e-DW for bug-gnu-emacs@gnu.org; Fri, 04 Mar 2016 16:39:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abxR8-0004jx-JQ for bug-gnu-emacs@gnu.org; Fri, 04 Mar 2016 16:39:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37018) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abxR8-0004ji-GA for bug-gnu-emacs@gnu.org; Fri, 04 Mar 2016 16:39:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1abxR8-00033G-8u for bug-gnu-emacs@gnu.org; Fri, 04 Mar 2016 16:39:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alain Schneble Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 04 Mar 2016 21:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22789 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 22789-submit@debbugs.gnu.org id=B22789.145712750711686 (code B ref 22789); Fri, 04 Mar 2016 21:39:02 +0000 Original-Received: (at 22789) by debbugs.gnu.org; 4 Mar 2016 21:38:27 +0000 Original-Received: from localhost ([127.0.0.1]:34145 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1abxQV-00032M-NR for submit@debbugs.gnu.org; Fri, 04 Mar 2016 16:38:27 -0500 Original-Received: from clientmail.realize.ch ([46.140.89.53]:2954) by debbugs.gnu.org with smtp (Exim 4.84) (envelope-from ) id 1abxQQ-000323-9q for 22789@debbugs.gnu.org; Fri, 04 Mar 2016 16:38:22 -0500 Original-Received: from rintintin.hq.realize.ch.lan.rit ([192.168.0.105]) by clientmail.realize.ch ; Fri, 4 Mar 2016 22:37:58 +0100 Original-Received: from MYNGB (192.168.250.224) by rintintin.hq.realize.ch.lan.rit (192.168.0.105) with Microsoft SMTP Server (TLS) id 15.0.516.32; Fri, 4 Mar 2016 22:37:20 +0100 In-Reply-To: <86egbqkwsb.fsf@realize.ch> (Alain Schneble's message of "Fri, 4 Mar 2016 17:55:32 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (windows-nt) X-ClientProxiedBy: rintintin.hq.realize.ch.lan.rit (192.168.0.105) To rintintin.hq.realize.ch.lan.rit (192.168.0.105) 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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:114431 Archived-At: --=-=-= Content-Type: text/plain Alain Schneble writes: > Eli Zaretskii writes: > >>> Date: Tue, 01 Mar 2016 18:05:36 +0200 >>> From: Eli Zaretskii >>> Cc: larsi@gnus.org, j_l_domenech@yahoo.com, 22789@debbugs.gnu.org >>> >>> IOW, let's return to the w32-specific issues when the dust settles on >>> the Posix code. >> >> It sounds like that part happened already, so do you still see any >> w32-specific issues with this? > > Sorry for the delay. It seems like there are still some issues, at > least on my system and even without any debugger attached. I'm > currently trying to find the cause... I have the impression that GnuTLS doesn't like it too much if we start retrying the handshake many times before the socket is connected. At least on MS-Windows. In nearly all of the cases of loading websites with around 20 images, I observe arbitrary failures of gnutls_try_handshake which usually end up with -10 GNUTLS_E_INVALID_SESSION. I believe this because the following patch solves the issue on my MS-Windows system: Postponing the handshake until after the socket is connected. Still, I must be honest: I'm in a kind of a trial-and-error mode. I do not really understand all the aspects of the current implementation. Anyway, I think a change in that direction would probably be a good thing. Do you agree? It eliminates all the handshake-retries that would otherwise happen before the socket is connected. I wonder if the issues that you observed with gdb attached would go away with this patch as well... You had these issues under GNU/Linux, right? It's a bit embarrassing, but I did not yet have time to learn how to use gdb to debug Emacs. (But its on my todo list.) Otherwise I would have tried it out quickly. BTW, `libgnutls-version' evaluates to 30408 on my MS-Windows. And here is the intermediate-and-not-cleaned-up patch: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename="0001-Wait-for-GnuTLS-handshake-until-socket-is-connected.patch" Content-Description: Patch >From cefaba56a33046b588eab81b3ca58224830a44f9 Mon Sep 17 00:00:00 2001 From: Alain Schneble Date: Fri, 4 Mar 2016 21:51:31 +0100 Subject: [PATCH] Wait for GnuTLS handshake until socket is connected * src/gnutls.c (emacs_gnutls_handshake, gnutls_try_handshake): Skip GnuTLS handshake when gnutls_boot is called on async socket (aka non blocking client). * src/process.c (connect_network_socket, wait_reading_process_output): Proceed with GnuTLS handshake only after async socket has been connected. --- src/gnutls.c | 11 ++++++++--- src/process.c | 9 ++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gnutls.c b/src/gnutls.c index 988c010..ddf4648 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -403,9 +403,6 @@ gnutls_try_handshake (struct Lisp_Process *proc) gnutls_session_t state = proc->gnutls_state; int ret; - if (proc->is_non_blocking_client) - proc->gnutls_p = true; - do { ret = gnutls_handshake (state); @@ -426,6 +423,8 @@ gnutls_try_handshake (struct Lisp_Process *proc) { /* check_memory_full (gnutls_alert_send_appropriate (state, ret)); */ } + + //printf ("gnutls_try_handshake: proc fd=%d, ret=%d\n", proc->infd, ret); return ret; } @@ -474,6 +473,12 @@ emacs_gnutls_handshake (struct Lisp_Process *proc) proc->gnutls_initstage = GNUTLS_STAGE_TRANSPORT_POINTERS_SET; } + if (proc->is_non_blocking_client) + { + proc->gnutls_p = true; + return GNUTLS_E_AGAIN; + } + return gnutls_try_handshake (proc); } diff --git a/src/process.c b/src/process.c index 4359f68..bd1c45f 100644 --- a/src/process.c +++ b/src/process.c @@ -3415,7 +3415,8 @@ connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses) if (p->gnutls_initstage == GNUTLS_STAGE_READY) /* Run sentinels, etc. */ finish_after_tls_connection (proc); - else if (p->gnutls_initstage != GNUTLS_STAGE_HANDSHAKE_TRIED) + else if ((! p->is_non_blocking_client && p->gnutls_initstage != GNUTLS_STAGE_HANDSHAKE_TRIED) || + (p->is_non_blocking_client && p->gnutls_initstage != GNUTLS_STAGE_TRANSPORT_POINTERS_SET)) { deactivate_process (proc); if (NILP (boot)) @@ -4950,8 +4951,10 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, #endif #ifdef HAVE_GNUTLS /* Continue TLS negotiation. */ - if (p->gnutls_initstage == GNUTLS_STAGE_HANDSHAKE_TRIED - && p->is_non_blocking_client) + if ((p->gnutls_initstage == GNUTLS_STAGE_TRANSPORT_POINTERS_SET || + p->gnutls_initstage == GNUTLS_STAGE_HANDSHAKE_TRIED) + && p->is_non_blocking_client + && (! FD_ISSET (p->outfd, &connect_wait_mask))) { gnutls_try_handshake (p); p->gnutls_handshakes_tried++; -- 2.6.2.windows.1 --=-=-=--