Libcurl - multiple requests crashing Apache

Avatar de Usuario
ricardo arraes
Mensajes: 87
Registered for: 3 years 5 months
Brazil

Libcurl - multiple requests crashing Apache

Mensaje por ricardo arraes »

Hey everybody, I'm having a problem with libcurl and apache, I don't really know what's going on... but let me explain you guys what's happening:

The user is multiclicking a button in my web application, so it is calling multiple times a my function sendhttp:
"multiclicking"=impacient users clicking on a button many times

Código: Seleccionar todo

curl_global_init(HB_CURL_GLOBAL_ALL)

  if ! empty( hCurl := curl_easy_init() )
    
    IF .NOT. Empty(cUrl)

      IF cHeader # NIL .AND. .NOT. Empty(cHeader)
        curl_easy_setopt( hCurl, HB_CURLOPT_HTTPHEADER, {"Authorization: "+cHeader} )
      ENDIF

      curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )  
      IF cHttp="POST"
        curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDS, "content="+curl_easy_escape(hCurl,hData))            
        ENDIF
      ENDIF
      curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )
      
      IF (nret:=curl_easy_perform( hCurl )) == 0
          uValue := curl_easy_dl_buff_get( hCurl )
      ENDIF
    ENDIF
  ENDIF
  
  curl_global_cleanup()   
basically, the application is trying to send many times the same request...

but this multiclick situation is crashing apache and displaying this error message in my error.log:

Código: Seleccionar todo

Unrecoverable error 6005: Exception error:

    Exception Code:C0000005 ACCESS_VIOLATION
    Exception Address:00007FFA25CB99D1
    RAX:00000051246AF0E0  RBX:00000051239CC338  RCX:0000000000388151  RDX:0000000000103A10
    RSI:00000051246AF1DC  RDI:0000000000000001  RBP:0000000000000000
    R8 :FFFFFFB17025C982  R9 :0000000000000000  R10:0000000000000860  R11:00000051246AE930
    R12:00000051246AF1D4  R13:0000000000000009  R14:00000051246AF1DC  R15:0000000000000000
    CS:RIP:0033:00007FFA25CB99D1  SS:RSP:002B:00000051246AF0A0
    DS:002B  ES:002B  FS:0053  GS:002B
    Flags:00010202
    Exception Parameters: 0000000000000000 00000051239CC338

Modules:
00007FF6DD950000 000000000000C000 C:\xampp\apache\bin\httpd.exe
00007FFA41910000 00000000001AD000 C:\Windows\SYSTEM32\ntdll.dll
00007FFA407E0000 000000000013F000 C:\Windows\system32\KERNEL32.DLL
00007FFA3EE80000 0000000000115000 C:\Windows\system32\KERNELBASE.dll
00007FFA34E70000 0000000000074000 C:\xampp\apache\bin\libhttpd.dll
0000000072630000 0000000000047000 C:\xampp\apache\bin\libaprutil-1.dll
00000000725F0000 0000000000038000 C:\xampp\apache\bin\libapr-1.dll
00007FFA3B120000 0000000000019000 C:\Windows\SYSTEM32\VCRUNTIME140.dll
00007FFA3B660000 0000000000004000 C:\Windows\SYSTEM32\api-ms-win-crt-runtime-l1-1-0.dll
00007FFA3B110000 0000000000004000 C:\Windows\SYSTEM32\api-ms-win-crt-stdio-l1-1-0.dll
00007FFA3B100000 0000000000004000 C:\Windows\SYSTEM32\api-ms-win-crt-string-l1-1-0.dll
00007FFA3B0B0000 0000000000005000 C:\Windows\SYSTEM32\api-ms-win-crt-math-l1-1-0.dll
00007FFA3B0A0000 0000000000003000 C:\Windows\SYSTEM32\api-ms-win-crt-locale-l1-1-0.dll
00007FFA3B090000 0000000000003000 C:\Windows\SYSTEM32\api-ms-win-crt-heap-l1-1-0.dll
00007FFA34E00000 0000000000065000 C:\xampp\apache\bin\pcre.dll
00007FFA40780000 000000000005A000 C:\Windows\system32\WS2_32.dll
00007FFA41850000 00000000000AA000 C:\Windows\system32\ADVAPI32.dll
00007FFA3A6F0000 0000000000004000 C:\Windows\SYSTEM32\api-ms-win-crt-convert-l1-1-0.dll
00007FFA3A6E0000 0000000000003000 C:\Windows\SYSTEM32\api-ms-win-crt-environment-l1-1-0.dll
00007FFA3A6D0000 0000000000003000 C:\Windows\SYSTEM32\api-ms-win-crt-utility-l1-1-0.dll
00007FFA3A6C0000 0000000000003000 C:\Windows\SYSTEM32\api-ms-win-crt-time-l1-1-0.dll
00000000725E0000 000000000000D000 C:\xampp\apache\bin\libapriconv-1.dll
00007FFA3E270000 0000000000059000 C:\Windows\SYSTEM32\MSWSOCK.dll
00007FFA40D70000 0000000000140000 C:\Windows\system32\RPCRT4.dll
00007FFA3F250000 000000000152A000 C:\Windows\system32\SHELL32.dll
00007FFA3A6B0000 0000000000003000 C:\Windows\SYSTEM32\api-ms-win-crt-conio-l1-1-0.dll
00007FFA34C40000 00000000000F4000 C:\Windows\SYSTEM32\ucrtbase.DLL
00007FFA41900000 0000000000009000 C:\Windows\system32\NSI.dll
00007FFA3F1A0000 00000000000AA000 C:\Windows\system32\msvcrt.dll
00007FFA40EB0000 0000000000059000 C:\Windows\SYSTEM32\sechost.dll
00007FFA3ED40000 000000000002E000 C:\Windows\system32\SspiCli.dll
00007FFA41060000 0000000000210000 C:\Windows\SYSTEM32\combase.dll
00007FFA40BF0000 0000000000177000 C:\Windows\system32\USER32.dll
00007FFA41630000 0000000000054000 C:\Windows\system32\SHLWAPI.dll
00007FFA40F10000 000000000014C000 C:\Windows\system32\GDI32.dll
00007FFA3F160000 0000000000036000 C:\Windows\system32\IMM32.DLL
00007FFA41270000 0000000000151000 C:\Windows\system32\MSCTF.dll
00007FFA3D090000 00000000000B2000 C:\Windows\SYSTEM32\shcore.dll
00007FFA3E2D0000 0000000000020000 C:\Windows\SYSTEM32\CRYPTSP.dll
00007FFA3DF10000 0000000000036000 C:\Windows\system32\rsaenh.dll
00007FFA3E520000 0000000000026000 C:\Windows\SYSTEM32\bcrypt.dll
00007FFA3E9B0000 000000000000B000 C:\Windows\SYSTEM32\CRYPTBASE.dll
00007FFA3E840000 0000000000063000 C:\Windows\SYSTEM32\bcryptPrimitives.dll
00007FFA34A70000 00000000000AD000 C:\xampp\apache\bin\libssl-1_1-x64.dll
00007FFA34300000 000000000034E000 C:\xampp\apache\bin\libcrypto-1_1-x64.dll
00007FFA34A60000 0000000000003000 C:\Windows\SYSTEM32\api-ms-win-crt-filesystem-l1-1-0.dll
00007FFA3A6A0000 0000000000009000 C:\xampp\apache\modules\mod_access_compat.so
00007FFA3A490000 0000000000008000 C:\xampp\apache\modules\mod_actions.so
00007FFA3A440000 000000000000A000 C:\xampp\apache\modules\mod_alias.so
00007FFA3A430000 0000000000007000 C:\xampp\apache\modules\mod_allowmethods.so
00007FFA385A0000 0000000000007000 C:\xampp\apache\modules\mod_asis.so
00007FFA38590000 0000000000009000 C:\xampp\apache\modules\mod_auth_basic.so
00007FFA38580000 0000000000009000 C:\xampp\apache\modules\mod_authn_core.so
00007FFA38570000 0000000000009000 C:\xampp\apache\modules\mod_authn_file.so
00007FFA38010000 000000000000A000 C:\xampp\apache\modules\mod_authz_core.so
00007FFA37BC0000 0000000000009000 C:\xampp\apache\modules\mod_authz_groupfile.so
00007FFA37960000 0000000000009000 C:\xampp\apache\modules\mod_authz_host.so
00007FFA37850000 0000000000007000 C:\xampp\apache\modules\mod_authz_user.so
00007FFA35940000 000000000000E000 C:\xampp\apache\modules\mod_autoindex.so
00007FFA35220000 000000000000A000 C:\xampp\apache\modules\mod_cgi.so
00007FFA34DF0000 000000000000A000 C:\xampp\apache\modules\mod_dav_lock.so
00007FFA34DD0000 000000000001B000 C:\xampp\apache\modules\mod_dav.so
00007FFA34DC0000 0000000000009000 C:\xampp\apache\modules\mod_dir.so
00007FFA34DB0000 0000000000008000 C:\xampp\apache\modules\mod_env.so
00007FFA34DA0000 000000000000A000 C:\xampp\apache\modules\mod_headers.so
00007FFA34D90000 0000000000010000 C:\xampp\apache\modules\mod_include.so
00007FFA34D80000 000000000000C000 C:\xampp\apache\modules\mod_info.so
00007FFA34C30000 000000000000C000 C:\xampp\apache\modules\mod_isapi.so
00007FFA34C20000 000000000000D000 C:\xampp\apache\modules\mod_log_config.so
00007FFA34C10000 000000000000C000 C:\xampp\apache\modules\mod_cache_disk.so
00007FFA34BF0000 0000000000012000 C:\xampp\apache\modules\mod_cache.so
00007FFA34BE0000 000000000000A000 C:\xampp\apache\modules\mod_mime.so
00007FFA34BD0000 000000000000D000 C:\xampp\apache\modules\mod_negotiation.so
00007FFA34BB0000 000000000001E000 C:\xampp\apache\modules\mod_proxy.so
00007FFA34BA0000 000000000000F000 C:\xampp\apache\modules\mod_proxy_ajp.so
00007FFA34B80000 0000000000014000 C:\xampp\apache\modules\mod_rewrite.so
00007FFA34B70000 0000000000009000 C:\xampp\apache\modules\mod_setenvif.so
00007FFA34B60000 000000000000A000 C:\xampp\apache\modules\mod_socache_shmcb.so
00007FFA34B20000 0000000000034000 C:\xampp\apache\modules\mod_ssl.so
00007FFA34A50000 000000000000B000 C:\xampp\apache\modules\mod_status.so
00007FFA34A40000 0000000000009000 C:\xampp\apache\modules\mod_version.so
00007FFA34A20000 000000000001B000 C:\xampp\apache\modules\mod_harbour.so
00007FFA20E00000 00000000008B7000 C:\xampp\php\php8ts.dll
00007FFA3EB10000 00000000001DF000 C:\Windows\system32\CRYPT32.dll
00007FFA3B040000 000000000002A000 C:\Windows\SYSTEM32\IPHLPAPI.DLL
00007FFA3EFC0000 0000000000194000 C:\Windows\system32\ole32.dll
00007FFA3E070000 00000000000A4000 C:\Windows\SYSTEM32\DNSAPI.dll
00007FFA3EAF0000 0000000000011000 C:\Windows\system32\MSASN1.dll
00007FFA3AFD0000 000000000000A000 C:\Windows\SYSTEM32\WINNSI.DLL
0000000180000000 0000000000048000 C:\xampp\php\libpq.dll
00007FFA39C30000 000000000000C000 C:\Windows\SYSTEM32\Secur32.dll
00007FFA415D0000 000000000005C000 C:\Windows\system32\WLDAP32.dll
00007FFA34A10000 000000000000D000 C:\xampp\php\php8apache2_4.dll
00007FFA34880000 000000000018A000 C:\xampp\php\libsqlite3.dll
00007FFA34860000 0000000000019000 C:\xampp\php\ext\php_bz2.dll
00007FFA347D0000 0000000000090000 C:\xampp\php\ext\php_curl.dll
00007FFA40920000 0000000000005000 C:\Windows\system32\Normaliz.dll
000000511FD00000 0000000000049000 C:\xampp\apache\bin\libssh2.dll
00007FFA347A0000 0000000000027000 C:\xampp\apache\bin\nghttp2.dll
00007FFA20780000 0000000000675000 C:\xampp\php\ext\php_fileinfo.dll
00007FFA34700000 0000000000012000 C:\xampp\php\ext\php_gettext.dll
00007FFA34190000 0000000000165000 C:\xampp\php\ext\php_mbstring.dll
00007FFA346E0000 0000000000015000 C:\xampp\php\ext\php_exif.dll
00007FFA346C0000 000000000001E000 C:\xampp\php\ext\php_mysqli.dll
00007FFA34790000 000000000000C000 C:\xampp\php\ext\php_pdo_mysql.dll
00007FFA346B0000 000000000000B000 C:\xampp\php\ext\php_pdo_sqlite.dll
00007FFA34680000 000000
Called from CURL_EASY_PERFORM(0)
Called from SENDHTTP(310) in pcode.hrb
Called from ACCESS:AUTH(63) in pcode.hrb
Called from __RUNCONTROLLER(9) in pcode.hrb
Called from HB_HRBDO(0)
Called from ZEXECUTE(217) in C:/xampp/htdocs/Site//lib/mercury/mercury.hrb
Called from TROUTE:EXECUTE(566) in C:/xampp/htdocs/Site//lib/mercury/mercury.hrb
Called from TROUTE:LISTEN(392) in C:/xampp/htdocs/Site//lib/mercury/mercury.hrb
Called from TAPP:INIT(139) in C:/xampp/htdocs/Site//lib/mercury/mercury.hrb
Called from MAIN(43) in pcode.hrb
Called from HB_HRBDO(0)
Does anybody know what is causing this strange behaviour?

by the way, preventing multiclik is not a solution because refreshing the page multiple times also causes this problem
Última edición por ricardo arraes el Mié Feb 10, 2021 2:42 am, editado 1 vez en total.
The work always comes before the belief

Avatar de Usuario
charly
Mensajes: 145
Registered for: 3 years 6 months

Mensaje por charly »

Hi Ricardo,

Si el proceso te funciona bien , yo montaria un patron PRG para evitar estos problemas con el F5. Hice una charla hace tiempo y lo publique en el foro antiguo, pero se perdio. Intentare buscar si tengo alguna copia, pero en cualquier caso hay mucha lectura, por ejemplo aqui https://es.m.wikipedia.org/wiki/Post/Redirect/Get

Esta tecnica es vital en paginas profesionales para evitar justamente estos casos

Piensa que haces un proceso que traspasa stock, dinero, .... y pulsas F5 REPETIDAMENTE. Pues posiblemente repetiras el proceso tantas veces. :lol:

Cualquier cosa aqui. ;)

C.
Salutacions, saludos, regards.
Charly

"...programar es fácil, hacer programas es difícil..."

https://httpd2.blogspot.com/
https://forum.modharbour.app

Avatar de Usuario
ricardo arraes
Mensajes: 87
Registered for: 3 years 5 months
Brazil

Mensaje por ricardo arraes »

Hey Charly!
Gracias!

I’m already using this pattern when sending http requests with post method but in this case, this happens even when I’m sending a get method.

For example, one of my application’s route is requesting information from the webservice, so it’s a get method:

Www.test.com/route?param=xxxx

So when user is multiclicking, libcurl is requesting it multiple times. That’s not a post form...

I don’t see a way of using PRG pattern in this situation because it must be synchronous...
The work always comes before the belief

Avatar de Usuario
charly
Mensajes: 145
Registered for: 3 years 6 months

Mensaje por charly »

Ricardo,

I understand your problem. When you execute GET you will send request to server. Then it will execute yiu request and just after curl, you shold need redirect to another page. This action avoid another request with f5
Salutacions, saludos, regards.
Charly

"...programar es fácil, hacer programas es difícil..."

https://httpd2.blogspot.com/
https://forum.modharbour.app

Avatar de Usuario
charly
Mensajes: 145
Registered for: 3 years 6 months

Mensaje por charly »

Ahhh now i see that its must be syncronous proc....

Let me think about it :D
Salutacions, saludos, regards.
Charly

"...programar es fácil, hacer programas es difícil..."

https://httpd2.blogspot.com/
https://forum.modharbour.app

Avatar de Usuario
charly
Mensajes: 145
Registered for: 3 years 6 months

Mensaje por charly »

And if you can try request ajax with syncronous option ?
Salutacions, saludos, regards.
Charly

"...programar es fácil, hacer programas es difícil..."

https://httpd2.blogspot.com/
https://forum.modharbour.app

Avatar de Usuario
ricardo arraes
Mensajes: 87
Registered for: 3 years 5 months
Brazil

Mensaje por ricardo arraes »

In fact it’s the opposite...

I send the curl request in order to get the information I need to render the page (redirect) with a list...

But you gave me an idea, Charly!

If I call the redirect() method before sending the curl request, I still can get the data and execute the rest of the function?
The work always comes before the belief

Avatar de Usuario
ricardo arraes
Mensajes: 87
Registered for: 3 years 5 months
Brazil

Mensaje por ricardo arraes »

Well, I can try using ajax... but i have many situations like that in my application, some of then the curl request must come from the harbour function because it comes after processing some data in harbour, do you understand? :)
The work always comes before the belief

Avatar de Usuario
charly
Mensajes: 145
Registered for: 3 years 6 months

Mensaje por charly »

No, you can't do it.

I will try in this case a request synchronous via ajax. When event is complet then i will send information to another page. Now i dont know how we can do all in server-side, i'm sorry

But its a good problem to solve

C.
Salutacions, saludos, regards.
Charly

"...programar es fácil, hacer programas es difícil..."

https://httpd2.blogspot.com/
https://forum.modharbour.app

Avatar de Usuario
ricardo arraes
Mensajes: 87
Registered for: 3 years 5 months
Brazil

Mensaje por ricardo arraes »

Ajax works synchronously, I alreasy use it in another situations. But as you said, the problem is when it’s a sever-side issue.

I thought curl_multi would be a solution, but I’m not so sure about it.

Is there any parameter in libcurl that could handle this kind of situation? I saw a lot of people in the internet complaining about it but haven’t found any solution yet...
The work always comes before the belief

Responder