unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alex Matei <matei.alexandru@live.com>
To: Eli Zaretskii <eliz@gnu.org>, Robert Pluim <rpluim@gmail.com>
Cc: "45821@debbugs.gnu.org" <45821@debbugs.gnu.org>
Subject: bug#45821: Emacs UDP support on Windows
Date: Mon, 2 Jan 2023 22:56:04 +0000	[thread overview]
Message-ID: <DB9PR02MB73371FB353278A3F6AA9CD6C85F79@DB9PR02MB7337.eurprd02.prod.outlook.com> (raw)
In-Reply-To: <83pmbx12gf.fsf@gnu.org>


[-- Attachment #1.1.1: Type: text/plain, Size: 5910 bytes --]

Thanks for the tips with logging!

I think I found the fix (at least for one of the issues?)
Please see the attached patch/diff for the fix.

The code will always  ignore (aka ‘eat’) one character if the file descriptor had the least significant bit set (0x1, so this would mean for any file descriptor with READ flag set)
[cid:image004.png@01D91EBA.5498F140]

Based on operator precedence rules, FILE_SOCKET == 0 will be evaluated first (before &) , resulting in 0, which would effectively cause the condition to always be false

This behavior can be observed when executing a call to  ‘(async-shell-command)’ (-> file descriptor flags 0x191) on a build with the patch vs one without the patch applied (see below, attached image)

  *   My suspicion is that this behavior is similar to what TLS was experiencing but just easier to reproduce (note: there might other issues with TLS , but so far, after applying this fix I have not run into any other issues)

[cid:image005.png@01D91EBA.5498F140]


@Robert Pluim<mailto:rpluim@gmail.com> I don’t know if this was the only missing piece, but from all my tests I couldn’t see any issues with TLS anymore, and with navigating https://gnu.org in EWW..
I wanted to thank you for creating this patch 🙏, and giving me pointers on how to apply and debug it.

In the meantime, I will continue to selfhost EWW and see if there are still other issues lurking around beyond this fix.


Funny enough, I ended up with good old ‘printf’, since it was nicely integrated with my build workflow: I would build and then just run emacs.exe from the shell => all my logging was nicely displayed there. ( message1 is also super nice, especially for useful user messages).


p.s.
- The patch also adds STATUS_READ_IN_PROGRESS state for the new ‘_sys_wait_readable’ function , based on what the read ahead logic was doing already (idk if it is needed, but it is a nice mirror, and a good status code to reflect, although I am not convinced anyone cares about this state transition..)
- I checked in other places of the code if we have issues with operator precedence for comparing socket flags, etc. and we are safe, most probably because we don’t bother with explicit equality conditions (like == 0) and instead we use the short form `if ( flag & socket_flag)`)

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

From: Eli Zaretskii<mailto:eliz@gnu.org>
Sent: Monday, January 2, 2023 5:38 AM
To: Robert Pluim<mailto:rpluim@gmail.com>
Cc: matei.alexandru@live.com<mailto:matei.alexandru@live.com>; 45821@debbugs.gnu.org<mailto:45821@debbugs.gnu.org>
Subject: Re: bug#45821: Emacs UDP support on Windows

> From: Robert Pluim <rpluim@gmail.com>
> Cc: matei.alexandru@live.com,  45821@debbugs.gnu.org
> Date: Mon, 02 Jan 2023 14:29:50 +0100
>
> >>>>> On Mon, 02 Jan 2023 14:41:00 +0200, Eli Zaretskii <eliz@gnu.org> said:
>
>     >> Cc: "45821@debbugs.gnu.org" <45821@debbugs.gnu.org>
>     >> From: Robert Pluim <rpluim@gmail.com>
>     >> Date: Mon, 02 Jan 2023 11:22:03 +0100
>     >>
>     Alex> ❌ Indeed, TLS is broken -> Eww to
>     >> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.gnu.org%2F&data=05%7C01%7C%7Cb554d88b24e74c4839a108daecc69c01%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638082635001245924%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2FqTmb2XqqC%2B9k7jFDvImdYlbUMXMJKCWJ3sNSV7hJVE%3D&reserved=0<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.gnu.org%2F&data=05%7C01%7C%7Cb554d88b24e74c4839a108daecc69c01%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638082635001245924%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2FqTmb2XqqC%2B9k7jFDvImdYlbUMXMJKCWJ3sNSV7hJVE%3D&reserved=0><https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.gnu.org%2F&data=05%7C01%7C%7Cb554d88b24e74c4839a108daecc69c01%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638082635001245924%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2FqTmb2XqqC%2B9k7jFDvImdYlbUMXMJKCWJ3sNSV7hJVE%3D&reserved=0%3chttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.gnu.org%2F&data=05%7C01%7C%7Cb554d88b24e74c4839a108daecc69c01%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638082635001245924%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2FqTmb2XqqC%2B9k7jFDvImdYlbUMXMJKCWJ3sNSV7hJVE%3D&reserved=0%3e> fails to load the page (
>     >> see attached image – Emacs instance on the left, compiled with UDP
>     >> patch, didn’t load gnu.org while on the right side- default Emacs
>     >> build for 28.1 opens it without any issues)
>     >>
>     >> Yep. Last time I looked at this, the TLS handshaking fails to complete
>     >> (see src/process.c around line 5329 and the checking against
>     >> GNUTLS_EMACS_HANDSHAKES_LIMIT) which means weʼre continually retrying
>     >> the handshake without giving the remote end a chance to send us
>     >> anything. Which I think means that our state machine for TLS
>     >> negotiation is subtly incorrect, but only on MS-Windows.
>
>     Eli> On MS-Windows, there's another state machine involved, the one
>     Eli> vis-a-vis the reader thread we start to read the stuff from the
>     Eli> network connection.  See reader_thread and sys_select in w32proc.c and
>     Eli> sys_write, sys_read, _sys_read_ahead, _sys_wait_accept, and
>     Eli> _sys_wait_connect in w32.c.
>
> Hmm, in that case I then suspect that `sys_select' is indicating that
> the socket it connected even when it isnʼt.

If that is the case, maybe we lack some flag(s) in the filedesc
structure.


[-- Attachment #1.1.2: Type: text/html, Size: 14553 bytes --]

[-- Attachment #1.2: 14D9BBA19389403AAE7B04F6D09528C2.png --]
[-- Type: image/png, Size: 32135 bytes --]

[-- Attachment #1.3: 22F9767EA55B4BA2BDE6B3027D69828E.png --]
[-- Type: image/png, Size: 86913 bytes --]

[-- Attachment #2: 45821-fix.txt --]
[-- Type: text/plain, Size: 1105 bytes --]

diff --git a/src/w32.c b/src/w32.c
index e11fa805f2..01a8616839 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -8928,7 +8928,7 @@ _sys_wait_readable (int fd)
   if (cp == NULL || cp->fd != fd || cp->status != STATUS_READ_READY)
     return STATUS_READ_ERROR;
 
-  cp->status = STATUS_READ_FAILED;
+  cp->status = STATUS_READ_IN_PROGRESS;
 
   hEv = pfn_WSACreateEvent ();
   rc = pfn_WSAEventSelect (SOCK_HANDLE (fd), hEv, FD_READ);
@@ -8944,6 +8944,8 @@ _sys_wait_readable (int fd)
       pfn_WSAEventSelect (SOCK_HANDLE (fd), NULL, 0);
       if (rc == WAIT_OBJECT_0)
         cp->status = STATUS_READ_SUCCEEDED;
+      else
+	cp->status = STATUS_READ_FAILED;
     }
   pfn_WSACloseEvent (hEv);
 
@@ -9078,7 +9080,7 @@ sys_read (int fd, char * buffer, unsigned int count)
 	    case STATUS_READ_SUCCEEDED:
 #ifdef WORKING_SELECT_EMULATION
               /* select on sockets no longer requires a 1-byte read.  */
-              if (fd_info[fd].flags & FILE_SOCKET == 0)
+              if ((fd_info[fd].flags & FILE_SOCKET) == 0)
 #endif
 		{
 		  /* consume read-ahead char */

  reply	other threads:[~2023-01-02 22:56 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-12 18:08 bug#45821: 28.0.50; Add UDP support for Emacs on Windows Lars Ingebrigtsen
2021-01-12 18:38 ` Eli Zaretskii
2021-01-13  9:17   ` Robert Pluim
2021-07-20 15:41     ` Lars Ingebrigtsen
2021-09-27 16:47       ` Robert Pluim
2021-09-27 17:45         ` Robert Pluim
2021-10-04 17:47           ` Robert Pluim
2021-10-04 17:59             ` Eli Zaretskii
2021-09-27 18:45         ` Eli Zaretskii
2021-10-11 11:56           ` Stefan Kangas
2021-10-11 12:06             ` Robert Pluim
2022-05-03 18:56 ` bug#45821: Emacs UDP support " Alex Matei
2022-05-04  7:35   ` Robert Pluim
2022-05-04 11:50     ` Alex Matei
2022-05-04 12:32       ` Robert Pluim
2022-09-11 11:26         ` bug#45821: 28.0.50; Add UDP support for Emacs " Lars Ingebrigtsen
2023-01-01 23:01         ` bug#45821: Emacs UDP support " Alex Matei
2023-01-02  0:47           ` Alex Matei
2023-01-02 10:22             ` Robert Pluim
2023-01-02 12:41               ` Eli Zaretskii
2023-01-02 13:29                 ` Robert Pluim
2023-01-02 13:38                   ` Eli Zaretskii
2023-01-02 22:56                     ` Alex Matei [this message]
2023-01-03  8:51                       ` Robert Pluim
2023-01-03 20:22                         ` Alex Matei
2023-01-04  9:32                           ` Robert Pluim
2023-01-04 10:15                             ` Alex Matei
2023-01-04 10:50                               ` Robert Pluim
2023-01-05 19:06                                 ` Alex Matei
2023-01-05 20:53                                   ` Alex Matei
2023-01-05 21:01                                     ` Alex Matei
2023-01-06  7:56                                       ` Robert Pluim
2023-01-07 11:24                                         ` Robert Pluim
2023-01-08 15:31                                           ` Alex Matei
2023-01-08 15:42                                             ` Robert Pluim
2023-01-08 15:43                                               ` Alex Matei
2023-01-08 16:00                                                 ` Alex Matei
2023-01-08 16:08                                                   ` Eli Zaretskii
2023-01-08 16:10                                                     ` Alex Matei
2023-01-10 12:41                                                       ` Alex Matei
2023-01-10 13:56                                                         ` Robert Pluim
2023-01-11 13:09                                                           ` Alex Matei
2023-01-11 13:23                                                             ` Alex Matei
2023-01-12  9:22                                                               ` Robert Pluim
2023-01-12 10:08                                                                 ` Eli Zaretskii
2023-01-12 10:14                                                                   ` Alex Matei
2023-01-12 10:24                                                                   ` Robert Pluim
2023-01-12 10:46                                                                     ` Eli Zaretskii
2023-01-12 10:57                                                                       ` Alex Matei
2023-01-12 10:59                                                                         ` Alex Matei
2023-01-12 11:03                                                                         ` Eli Zaretskii
2023-01-12 11:12                                                                           ` Alex Matei
2023-01-12 11:21                                                                             ` Robert Pluim
2023-01-12 11:23                                                                               ` Alex Matei
2023-01-12 11:18                                                                       ` Robert Pluim
2023-01-12 12:25                                                                         ` Eli Zaretskii
2023-01-12 13:28                                                                           ` Robert Pluim
2023-01-28 21:17                                                                             ` Alex Matei
2023-01-29  6:13                                                                               ` Eli Zaretskii
2023-01-02 10:10           ` Robert Pluim
2023-01-02 16:01             ` Alex Matei
2023-01-03 13:30               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-03 19:18                 ` Alex Matei
2023-01-02 12:07           ` Eli Zaretskii
2023-01-02 15:59             ` Alex Matei
2023-01-02 17:01               ` Eli Zaretskii
2023-01-02 17:57                 ` Alex Matei
2023-01-02 19:07                   ` Alex Matei
2023-01-02 19:22                     ` Eli Zaretskii
2023-01-02 19:24                       ` Alex Matei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DB9PR02MB73371FB353278A3F6AA9CD6C85F79@DB9PR02MB7337.eurprd02.prod.outlook.com \
    --to=matei.alexandru@live.com \
    --cc=45821@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=rpluim@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).