softtouch 9 Posted June 15, 2023 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
Angus Robertson 574 Posted June 15, 2023 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
FPiette 383 Posted June 15, 2023 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
Fr0sT.Brutal 900 Posted June 15, 2023 (edited) 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 June 15, 2023 by Fr0sT.Brutal Share this post Link to post
softtouch 9 Posted June 15, 2023 (edited) 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 June 15, 2023 by softtouch Share this post Link to post
Angus Robertson 574 Posted June 15, 2023 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
softtouch 9 Posted June 15, 2023 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
Fr0sT.Brutal 900 Posted June 15, 2023 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
softtouch 9 Posted June 16, 2023 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
Angus Robertson 574 Posted June 16, 2023 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 1 Share this post Link to post
Fr0sT.Brutal 900 Posted June 19, 2023 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