Subject: bug#73199: url-retrieve is not thread-safe

From: Michael Albinus <[email-masked]>
Date: Thu, 10 Oct 2024 13:29:42 +0200

Michael Albinus <[email-masked]> writes:

> Eli Zaretskii <[email-masked]> writes:
>
>>> From: Michael Albinus <[email-masked]>
>>> Cc: [email-masked],  [email-masked],  [email-masked],
>>>   [email-masked]
>>> Date: Mon, 30 Sep 2024 18:42:55 +0200
>>>
>>> Oops, sorry. I've appended the vc-dir buffer, not the vc-diff ...
>>
>> Thanks.  I'd appreciate if you could explain why url-retrieve is
>> currently not thread-safe, and how this patch is supposed to solve
>> that.
>
> In <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=73199#14>, there's a
> recipe for reproduction.
>
> The general problem is when you want to access the same HTTP server from
> a different thread, and url-http-attempt-keepalives is set to t. This
> happens, for example, in debbugs 0.41.
>
> Let's assume, there is an access to debbugs:443 from a given thread, for
> example the main thread. Soap-client serves. It also binds
> url-http-attempt-keepalives to t, the https process stays alive.
>
> Later on, there is an access to debbugs:443 from another thread. It
> checks, whether there is a running process for that target, and tries to
> reuse. We get the error
>
> Error #<thread debbugs>: (error "Attempt to accept output from process debbugs.gnu.org locked to thread #<thread 0xc288a0>")
>
> My patch tries to fix this. The list of still open processes is the hash
> table url-http-open-connections. It has the ky (cons host port), and as
> value a list of processes.
>
> My patch changes this such a way, that the key is now (list host port
> thread). Therefore, only open processes which belong to the same thread
> are checked.
>
> This seems to work sufficiently.

Ping. Any comments? Otherwise, I'll install the patch in a couple of days.

Best regards, Michael.