Page 1 of 1
Add HTTPTimeout
Posted: Fri Mar 13, 2020 4:03 pm
by wayne-c
It seems as AbortHTTP is working only when the download already began and is in progress, but not working while the connection is in progress? I have a server that exists but does not respond within 30 seconds, when I send an AbortHTTP after 5 secs, nothing happens (I expect to receive a #PB_HTTP_Aborted, which never arrives...)
Re: AbortHTTP not working while connecting
Posted: Fri Mar 13, 2020 5:14 pm
by wayne-c
Maybe this is only visible inside the purebasic source, so @Fred could you please verify this?
Re: AbortHTTP not working while connecting
Posted: Fri Mar 13, 2020 11:38 pm
by infratec
I think the main problem is that no (user definable) timeout is implemented.
Since the http is not in progress ...
you can not 'abort' the connection state.
Re: AbortHTTP not working while connecting
Posted: Sat Mar 14, 2020 9:41 am
by Fred
Moved to bug report for investigation
Re: AbortHTTP not working while connecting
Posted: Sat Mar 14, 2020 10:20 am
by wayne-c
Thanks for investigating, Fred.
As a workaround in the meantime, is it safe to implement a "hard" break like in the following code, or does this lead to internal memory leaks?
Code: Select all
TickTimeout.q = ElapsedMilliseconds() + 1000 ; Timeout after 1sec
Request = HTTPRequest(#PB_HTTP_Post, "https://xxxxxxxxx/xxx/xxxService_v1", "Post Data here", #PB_HTTP_Asynchronous | #PB_HTTP_NoSSLCheck)
If Request
Debug "STARTED"
Repeat
Progress = HTTPProgress(Request)
Select Progress
Case #PB_HTTP_Success
Debug "SUCCESS"
Response$ = HTTPInfo(Request, #PB_HTTP_Response)
FinishHTTP(Request)
Break
Case #PB_HTTP_Failed
FinishHTTP(Request)
Response$ = "FAILED"
Debug "FAILED"
Break
Case #PB_HTTP_Aborted
FinishHTTP(Request)
Response$ = "ABORTED"
Debug "ABORTED"
Break
Default
Debug "PROGRESS = " + Progress
EndSelect
If ElapsedMilliseconds() > TickTimeout
Debug "ABOUT TO ABORT"
;--- HARD ABORT WHILE CONNECTING ---
If Progress = 0
FinishHTTP(Request)
Debug "HARD ABORT WHILE CONNECTING"
Break
EndIf
AbortHTTP(Request)
EndIf
Delay(250)
ForEver
EndIf
Re: AbortHTTP not working while connecting
Posted: Mon Mar 23, 2020 10:39 am
by Fred
Do you mean it never returned anything ?
Re: AbortHTTP not working while connecting
Posted: Mon Mar 23, 2020 10:43 am
by wayne-c
Fred wrote:Do you mean it never returned anything ?
I would like to cancel the async request after a specific timeout, so after my period of waiting time I manually call AbortHTTP(). This gives the internal HTTP functions the possibility to end and cleanup, I would then expect to receive a #PB_HTTP_Abort status afterwards which lets me quit my loop. This works fine while downloading a file is in progress, but while connecting, this does not work, I do never receive an abort status.
Re: AbortHTTP not working while connecting
Posted: Mon Mar 23, 2020 10:47 am
by Fred
I will add an HTTPTimeout() function to allow to specify one, as clearing the request as you did can lead to crash when the internal libcurl timeout is reached.
Re: AbortHTTP not working while connecting
Posted: Mon Mar 23, 2020 10:49 am
by wayne-c
Fred wrote:I will add an HTTPTimeout() function to allow to specify one, as clearing the request as you did can lead to crash when the internal libcurl timeout is reached.
That would be perfect!

Re: AbortHTTP not working while connecting
Posted: Tue Mar 31, 2020 9:43 am
by wayne-c
Fred wrote:I will add an HTTPTimeout() function to allow to specify one, as clearing the request as you did can lead to crash when the internal libcurl timeout is reached.
Too bad this feature did not make it into the release. Hopefully another beta will come soon.
Re: Add HTTPTimeout
Posted: Tue Mar 31, 2020 9:46 am
by Fred
Yes, we need to freeze the dev at one point or it will never have any release

Re: Add HTTPTimeout
Posted: Tue Mar 31, 2020 10:01 am
by Derren
Fred wrote:Yes, we need to freeze the dev at one point or it will never have any release

Always in Beta, just like Microsoft Windows. Just call it "evergreen"
