Subject: bug#45821: Emacs UDP support on Windows

From: Alex Matei <[email-masked]>
Date: Tue, 3 Jan 2023 20:22:58 +0000

Here are the 2 patches that can be applied, in order:

  *   0001 -> the original patch from the email thread, that I used
  *   0002 -> the additions that I made locally

Note: TLS mostly works, but I’ve observed some weird behavior in the process list for EWW

  *   It almost feels like sometimes we hit snags in navigating to some HTTPS endpoints because the existing connections never get closes
  *   I think we need to make some investigations/ changes to the socket lifetime / close behavior to fix the class of issues we are seeing in EWW, where sometimes the page load hangs, and yes, you can load it after a couple of refreshes (‘g’ key binding) but then you see something really interesting if you take a look at the process list
     *   You will notice that some of the connection never close (properly) and hang around!
     *   If anyone has any good pointers of what are good functions to look at, please let me know; I will take a look at this later in the day, and navigate the reader thread and everything around it..

p.s. I didn’t find an obvious way of merging the two patches in magit, hence the 2 individual patches 😊 – I guess I can just rebase the commits into one..

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

From: Robert Pluim<mailto:[email-masked]>
Sent: Tuesday, January 3, 2023 12:51 AM
To: Alex Matei<mailto:[email-masked]>
Cc: Eli Zaretskii<mailto:[email-masked]>; [email-masked]<mailto:[email-masked]>
Subject: Re: bug#45821: Emacs UDP support on Windows

>>>>> On Mon, 2 Jan 2023 22:56:04 +0000, Alex Matei <[email-masked]> said:

    Alex> Thanks for the tips with logging!
    Alex> I think I found the fix (at least for one of the issues?)
    Alex> Please see the attached patch/diff for the fix.

    Alex> The code will always ignore (aka ‘eat’) one character if the file
    Alex> descriptor had the least significant bit set (0x1, so this would mean
    Alex> for any file descriptor with READ flag set)
    Alex> 

Hmm, my local version already had that fixed, so I guess I posted the
wrong patch to the bug. But I still think you found a fix (see below)

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

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

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

    Alex> 

    Alex> @Robert Pluim<mailto:[email-masked]> I don’t know if this was the
    Alex> only missing piece, but from all my tests I couldn’t see any issues
    Alex> with TLS anymore, and with navigating https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgnu.org%2F&data=05%7C01%7C%7C4f957b24a1204b5c8e5608daed67ab41%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638083326770863958%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=oe0n96z7hwrRvkyKmiiG6Bpjn21g5OUcgkeV6pklPs4%3D&reserved=0 in EWW..
    Alex> I wanted to thank you for creating this patch 🙏, and giving me pointers on how to apply and debug it.

Iʼd run the networking portion of our test suite to see if everything
works as intended (you might need to install the GnuTLS cli tools). eg:

    cd test
    make network-stream-tests

    Alex> p.s.
    Alex> - The patch also adds STATUS_READ_IN_PROGRESS state for the new
    Alex> ‘_sys_wait_readable’ function , based on what the read ahead logic was
    Alex> doing already (idk if it is needed, but it is a nice mirror, and a
    Alex> good status code to reflect, although I am not convinced anyone cares
    Alex> about this state transition..)

I think this is actually the fix, since I added it locally and TLS
started working, but I donʼt understand the code enough to be definite
about that. More testing required 😀

Can you post the full patch just to ensure weʼre all talking about the
same changes? Iʼve attached what Iʼm working from

Robert
--