[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libmicrohttpd] MHD_AccessHandlerCallback won't be called again if *
From: |
Christian Grothoff |
Subject: |
Re: [libmicrohttpd] MHD_AccessHandlerCallback won't be called again if *upload_data_size is set to non-zero. |
Date: |
Sat, 16 Jul 2016 22:08:22 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 |
Hi Nicholas,
I've looked at the code, and I don't think this is a bug in MHD.
Basically, the issue is that you're telling MHD that you cannot
immediately process all POST data (by partially handling the data).
But MHD never does busy waiting, and we have now no way of telling
when your application might be ready to handle the rest of the POST.
MHD's behavior in this case is to avoid the busy loop, and instead
simply retry at the next opportunity, which as you rightly observe
might be 'never'. I've clarified that we consider this an application
bug by printing a warning in SVN 37545 whenever an application behaves
"badly" in this sense.
The correct behavior (for your code) would be to call
MHD_suspend_connection() as you are returning from handling the POST
partially (with more than 0-bytes left in upload data). Then, once you
are ready to handle the rest of the data, you should call
MHD_resume_connection(). Alternatively, in "thread-per-connection"
mode, you should block until you've processed all the data. Only in
"external" select mode, you don't have to suspend the connection as you
can force MHD to re-trigger the handler by calling MHD_run().
As of SVN 37545, MHD now logs a warning if applications keep data
unprocessed while also not suspending the connection and also not
running in external select mode. I hope this will help everyone in (1)
finding these corner cases, and (2) understanding how to handle them
properly.
Happy hacking!
Christian
On 07/14/2016 06:34 AM, Nicholas Cooper wrote:
> Hi,
>
> Let's say the access handler callback passed to MHD_start_daemon() is
> answer_to_connection(). According to the comment in microhttpd.h, the
> parameter upload_data_size shall be updated to the number of bytes not
> processed. However, it seems that it only works perfectly if the
> *upload_data_size is updated to zero. If its value is set to non-zero,
> answer_to_connection() won't be called again, which leaves the HTTP
> client waiting forever. To be more exact, unless the client sends
> another (unrelated) request, MHD calls answer_to_connection() for the
> suspending request again. Don't know if this is a bug, or I'm misusing
> MHD. Having tried this on both Linux (Debian) and Windows, and both
> don't work. The attached file demonstrates the problem.
>
> Thanks. Have a nice day.
>
> Nicholas Cooper.
signature.asc
Description: OpenPGP digital signature