libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] race condition on 0.9.73


From: Evgeny Grin
Subject: Re: [libmicrohttpd] race condition on 0.9.73
Date: Sat, 25 Sep 2021 17:02:24 +0300
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0

Hi José,

-------- Original Message --------
From: José Bollo <jobol@nonadev.net>
Sent: Friday, September 24, 2021, 15:56 UTC+3
Subject: [libmicrohttpd] race condition on 0.9.73

Hi Evgeny, Hi all,

Firstly, protecting MHD_run made the job, the crash disappears and
valgrind is happy. Thank you for that efficient support.

You are welcome.


Secundly, I'm still seeing and investigating an issue. Sometime, the
queued response (MHD_queue_response) is not sent. Here again, I think
that it is a race condition. The issue is surely on my side.

Make sure that you are not sending response when callback is called for the first time for request. The first call is just for notification, if you send response immediately, connection will be closed after response.
NOTE: we are going to change this behaviour in backward-compatible way.

Don't you use MHD built-in "upgrade" functions?

Good question. I had not noticed before: I have both options
MHD_ALLOW_UPGRADE and MHD_ALLOW_SUSPEND_RESUME. When I first
implemented websocket using MHD, I used the suspend/resume behaviour.
Is it still needed? I am now using MHD_create_response_for_upgrade for
that purpose.

MHD_ALLOW_UPGRADE is needed if you use MHD "upgrade" functions, MHD_ALLOW_SUSPEND_RESUME is needed if you use suspend and resume of connections. If you suspend connection for direct dealing with socket, make sure that you resume connection after finished with socket and before calling MHD_stop_daemon().
I recommend you to add MHD_USE_ERROR_LOG flag at least for testing.
You can use this flag (probably with MHD_OPTION_EXTERNAL_LOGGER option) for production builds.
Information in MHD log could give you some hints.

However, at the moment, the program suspend the connection for the time
it processes the request. That is the reason way MHD_run were called
from multiple threads.

You can still run MHD with MHD internal threads and connection suspend. Response can be added to suspended connection in any thread.

--
Wishes,
Evgeny

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]