risoflora / brookframework

Microframework which helps to develop web Pascal applications.
https://risoflora.github.io/brookframework
GNU Lesser General Public License v2.1
240 stars 54 forks source link

Error during select (9): `Bad file descriptor' #50

Open Al-Muhandis opened 12 months ago

Al-Muhandis commented 12 months ago

What kind of bug could it be? Where can I find information?

[EBrookHTTPServer] Error during select (9): `Bad file descriptor'

Second error (other times):

Fatal error in GNU libmicrohttpd /root/libsagui-3.4.1/lib/libmicrohttpd-0.9.76/src/microhttpd/daemon.c:3845: Close socket failed.

I localized an interesting point. The error sometimes occurs if the FCL httpclient is used in one of the worker threads. If the client in the thread does not cause such errors never occurs

Thanks

Al-Muhandis commented 11 months ago

If it helps. The error certainly happens only if there are requests to secure site addresses when using the FP HTTPClient client.

Occurs under heavy load, as I understand, because in other projects such problems are not observed.

The code inside cycle with bulk count of aDomainName


      aHTTP.AllowRedirect:=True;                    
      if aIsHTTPS then
        aProt:='https'
      else
        aProt:='http';
      s:=aProt+'://'+aDomainName;
      aHTTP.Get(s, aResponse);
      aCode:=aHTTP.ResponseStatusCode;          

If not IsHTTPS then it's ok . if IsHTTPS is set then at any random turn of the cycle (there is no specific domain name because of which this happens), the application crashes with the above system daemon error. The error catching is not helps: app crashs always after this

Al-Muhandis commented 11 months ago

The place in the microhttpd library where this error supposedly occurs, judging by the logs. I guess it's a bug in this place:

#ifdef EPOLL_SUPPORT
 3849     if (0 != (daemon->options & MHD_USE_EPOLL))
 3850     {
 3851       if (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
 3852       {
 3853         EDLL_remove (daemon->eready_head,
 3854                      daemon->eready_tail,
 3855                      pos);
 3856         pos->epoll_state &=
 3857           ~((enum MHD_EpollState) MHD_EPOLL_STATE_IN_EREADY_EDLL);
 3858       }
 3859       if ( (-1 != daemon->epoll_fd) &&
 3860            (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) )
 3861       {
 3862         /* epoll documentation suggests that closing a FD
 3863            automatically removes it from the epoll set; however,
 3864            this is not true as if we fail to do manually remove it,
 3865            we are still seeing an event for this fd in epoll,
 3866            causing grief (use-after-free...) --- at least on my
 3867            system. */

https://fossies.org/linux/libmicrohttpd/src/microhttpd/daemon.c

silvioprog commented 9 months ago

Hey @Al-Muhandis, could you try again using Sagui 3.4.4?

Al-Muhandis commented 9 months ago

Hey @Al-Muhandis, could you try again using Sagui 3.4.4?

Hi! Thanks. I will try!