Jump to content
softtouch

No timeout in THttpCli?

Recommended Posts

I need to set a connect- and read timeout, but cant find any property in THttpCli (Tsslhttpcli) for that. The provides timeout property seems not to do anything. I know, I could use a timer and reset it every time data is received, but I am running 500 threads and that would mean having 500 timer, makes no sense. So why is there no connect timeout and receive timeout like in other http clients?

Share this post


Link to post

The timeout property is for synchronous methods, wait x seconds for a reply, perhaps you are using async methods? 

 

ICS is mostly used async, so hundreds of parallel requests can be made without needing threads. The only issue will be DNS look-ups which are effectively blocking. 

 

Angus

 

Share this post


Link to post
34 minutes ago, softtouch said:

but I am running 500 threads

Not the best idea in the world!

Tell us why you need so much threads?

Look at OverbyteIcsHttpAsy demo project to get inspiration.

 

Share this post


Link to post
52 minutes ago, Angus Robertson said:

The only issue will be DNS look-ups which are effectively blocking. 

Hmm AsyncResolve has been there for long time.

1 hour ago, softtouch said:

cant find any property in THttpCli (Tsslhttpcli) for that

THttpCli.CtrlSocket.TimeoutConnect/Idle if ICS is built with BUILTIN_TIMEOUT define (default)

Edited by Fr0sT.Brutal

Share this post


Link to post
56 minutes ago, Fr0sT.Brutal said:

Hmm AsyncResolve has been there for long time.

THttpCli.CtrlSocket.TimeoutConnect/Idle if ICS is built with BUILTIN_TIMEOUT define (default)

That does not do anything, no timeout or exception or whatever is triggered.

 

Setting the httpcli.timeout works, if I use Get and not GetASynch. Using GetASynch is not triggering anything for me.

 

If I do a Get to this example site: https://www.cars.com I get a timeout which I can catch with try/except/end, using GetASynch, nothing happen, I can wait hours without anything happen. How do I catch the timeout using GetASynch?

Edited by softtouch

Share this post


Link to post
Quote

Using GetASynch is not triggering anything for me.

Correct, as designed, there is no timeout if you use the async methods, only sync.  

 

In my applications that use multiple components in parallel with async methods, and in the ICS servers, I use a single timer that loops through all active connections checking duration and cancels any taking too long.  

 

If you are using threads, you must have something in the Execute method looping waiting for an async result, so use a tick counter there.

 

Angus

 

Share this post


Link to post
4 minutes ago, Angus Robertson said:

Correct, as designed, there is no timeout if you use the async methods, only sync.  

 

In my applications that use multiple components in parallel with async methods, and in the ICS servers, I use a single timer that loops through all active connections checking duration and cancels any taking too long.  

 

If you are using threads, you must have something in the Execute method looping waiting for an async result, so use a tick counter there.

 

Angus

 

Thanks, yes, looks like I have to use a timer or gettickcount or something else then.

Share this post


Link to post
3 hours ago, softtouch said:

That does not do anything, no timeout or exception or whatever is triggered.

Have you assigned Socket's OnTimeout as well?

Share this post


Link to post
12 hours ago, Fr0sT.Brutal said:

Have you assigned Socket's OnTimeout as well?

Yes, I did, and it did not do anything, no timeout triggered.

Share this post


Link to post

In order to provide a timeout for async methods, the component would need to include a timer, using an extra handle and resources. When you have 100 components running in parallel, that is very inefficient, thus the design where the application is responsible for timing out unresponsive components.   Some server components do include a timer for that purpose, but rarely do applications need more than one server component. 

 

Angus

 

  • Like 1

Share this post


Link to post
On 6/16/2023 at 7:52 AM, softtouch said:

Yes, I did, and it did not do anything, no timeout triggered.

procedure TForm1.SocketTimeout(Sender: TObject; Reason: TTimeoutReason);
begin
  case Reason of
    torConnect : Log('conn timeout');
    torIdle    : Log('idle timeout');
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  HttpCli1.CtrlSocket.TimeoutConnect := 3000;
  HttpCli1.CtrlSocket.TimeoutIdle := 4000;
  HttpCli1.CtrlSocket.OnTimeout := SocketTimeout;
  HttpCli1.URL := 'example.com:802/';
  HttpCli1.Head;
end;

This fires "conn timeout" event. However this needs polishing because ~20secs later the "httpHEAD: Error# 10060Winsock - Connection timed out (Error #10060) to 93.184.216.34:802." raises.

I only use plain ICS sockets not HTTPCli so I can't say much about it but timeouts of plain sockets work very well in my app where I have ~300 of them.

On 6/16/2023 at 10:52 AM, Angus Robertson said:

In order to provide a timeout for async methods, the component would need to include a timer, using an extra handle and resources

I always thought IcsThreadTimer was created exactly to solve this issue

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×