Add HTTPTimeout

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
wayne-c
Enthusiast
Enthusiast
Posts: 335
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Add HTTPTimeout

Post 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...)
As you walk on by, Will you call my name? Or will you walk away?
wayne-c
Enthusiast
Enthusiast
Posts: 335
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Re: AbortHTTP not working while connecting

Post by wayne-c »

Maybe this is only visible inside the purebasic source, so @Fred could you please verify this?
As you walk on by, Will you call my name? Or will you walk away?
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: AbortHTTP not working while connecting

Post 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.
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: AbortHTTP not working while connecting

Post by Fred »

Moved to bug report for investigation
wayne-c
Enthusiast
Enthusiast
Posts: 335
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Re: AbortHTTP not working while connecting

Post 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
As you walk on by, Will you call my name? Or will you walk away?
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: AbortHTTP not working while connecting

Post by Fred »

Do you mean it never returned anything ?
wayne-c
Enthusiast
Enthusiast
Posts: 335
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Re: AbortHTTP not working while connecting

Post 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.
As you walk on by, Will you call my name? Or will you walk away?
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: AbortHTTP not working while connecting

Post 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.
wayne-c
Enthusiast
Enthusiast
Posts: 335
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Re: AbortHTTP not working while connecting

Post 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! :D
As you walk on by, Will you call my name? Or will you walk away?
wayne-c
Enthusiast
Enthusiast
Posts: 335
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Re: AbortHTTP not working while connecting

Post 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.
As you walk on by, Will you call my name? Or will you walk away?
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Add HTTPTimeout

Post by Fred »

Yes, we need to freeze the dev at one point or it will never have any release :)
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: Add HTTPTimeout

Post 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" :mrgreen:
Post Reply