Libcurl - Access_violation

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!
Post Reply
User avatar
ricbarraes
Posts: 49
Joined: Tue Jun 30, 2015 2:26 am
Location: Brazil

Libcurl - Access_violation

Post by ricbarraes »

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

Code: Select all

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:

Code: Select all

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
Sds,
Ricardo Arraes
ricardo@vfatec.com.br
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Libcurl - Access_violation

Post by Antonio Linares »

Ricardo,

Using threads may be a solution :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
ricbarraes
Posts: 49
Joined: Tue Jun 30, 2015 2:26 am
Location: Brazil

Re: Libcurl - Access_violation

Post by ricbarraes »

Hey Antonio!

Can iI use threads in mod_harbour the same way I do it in my desktop applications??

Is there any sample?

Thank you!!
Sds,
Ricardo Arraes
ricardo@vfatec.com.br
User avatar
ricbarraes
Posts: 49
Joined: Tue Jun 30, 2015 2:26 am
Location: Brazil

Re: Libcurl - Access_violation

Post by ricbarraes »

Hey everybody...

I found out that the solution is WAAAAAY simpler than we were discussing...

ridiculously simple...

First of all, let's go back to the libcurl documentation...

we can see right in the introduction that libcurl is THREAD-FREE.
*which means that libcurl has no problem with parallel requests

https://curl.se/libcurl/

So why is this problem happening???
well, here we can see that "are a few exceptions" for that thread-free behaviour.

https://curl.se/libcurl/features.html#thread

In this other page right here we can see that curl_global* methods are NOT thread-safe...

https://curl.se/libcurl/c/threadsafe.html

with that been said, we just found out the reason why this is happening...

we gotta take these curl_global* methods off like that:

Code: Select all


//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"
        IF lHash # NIL .AND. lHash     
          curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDS, "conteudo="+curl_easy_escape(hCurl,hData))            
        ELSE
          curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDS, "conteudo="+curl_easy_escape(hCurl,hb_crypt(hb_jsonEncode(hData),AP_GetEnv( "ENCRYPT" ))))    
        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() 
  curl_easy_cleanup(hCurl)   
 
and now it works properly...

it's really hard to believe that it was THAT simple...
:lol:
Sds,
Ricardo Arraes
ricardo@vfatec.com.br
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Libcurl - Access_violation

Post by Antonio Linares »

many thanks for sharing it :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply