It is currently Sun Sep 22, 2019 1:32 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [Done] Repeatedly called async HTTPRequest() will crash
PostPosted: Sat Jul 06, 2019 9:16 pm 
Offline
User
User

Joined: Tue Feb 14, 2006 2:00 pm
Posts: 63
Hi,

when I will run this code then it works for short while (one second) and then it will crash at the line 4. Only when #PB_HTTP_Asynchronous is used. I am doing something wrong?

Also after FinishHTTP(HTTPRequest) is the HTTPRequest value not cleared, is that intentional behavior?

Code:
status = 0
Repeat
  If status = 0
    HttpRequest = HTTPRequest(#PB_HTTP_Post, "https://www.google.com", "", #PB_HTTP_Asynchronous)
    If HttpRequest
      status = 1
      Debug "started"
    EndIf
  EndIf
 
  If status = 1
    Progress = HTTPProgress(HttpRequest)
    If Progress = #PB_HTTP_Success Or Progress = #PB_HTTP_Failed Or Progress = #PB_HTTP_Aborted
      FinishHTTP(HTTPRequest) 
      status = 0
      Debug "finished"
    EndIf
  EndIf
ForEver


Result:
[21:57:35] Waiting for executable to start...
[21:57:35] Executable type: Windows - x86 (32bit, Unicode)
[21:57:35] Executable started.
[21:57:37] [ERROR] Line: 4
[21:57:37] [ERROR] Invalid memory access. (read error at address 108511263)
[21:57:37] The Program execution has finished.

After this crash any further execution of Purebasic code can start crashig on random lines (opening windows for example) and it needs a restart. But in this small piece of code it will not happen.

Happens on:
PureBasic_Windows_5.71_beta_2_x86_(ya20se)
PureBasic_5_70_x86_LTS_(aug4p7)


Top
 Profile  
Reply with quote  
 Post subject: Re: Repeatedly called async HTTPRequest() will crash
PostPosted: Sat Jul 06, 2019 11:03 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4311
Location: Germany
Hi,

you are right, there is a bug.
It looks that it is timing related.

If you use more time after receiving it works.
Code:
InitNetwork()

Repeat
 
  If status = 0
    HttpRequest = HTTPRequest(#PB_HTTP_Get, "https://www.google.com", "", #PB_HTTP_Asynchronous)
    If HttpRequest
      status = 1
      Debug "started"
    EndIf
  EndIf
 
  If status = 1
    Progress = HTTPProgress(HttpRequest)
;    Debug Progress
    If Progress = #PB_HTTP_Success Or Progress = #PB_HTTP_Failed Or Progress = #PB_HTTP_Aborted
     
      If Progress = #PB_HTTP_Success
        *Buffer = HTTPMemory(HTTPRequest)
        Debug PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8|#PB_ByteLength)
        FreeMemory(*Buffer)
      EndIf
     
      FinishHTTP(HTTPRequest)
      status = 0
      Debug "finished"
    EndIf
  EndIf
 
ForEver


And if you use asynchronous, you should enable thread safe in compileroptions.

And yes FinishHTTP doesn't set the variable to 0. But that's 'normal'.
FreeMemory(), for example, also doesn't set the variable to 0.


Top
 Profile  
Reply with quote  
 Post subject: Re: Repeatedly called async HTTPRequest() will crash
PostPosted: Fri Aug 09, 2019 12:35 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13612
Location: France
Fixed.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye