Recent

Author Topic: idHTTP (Indy10): hangs  (Read 3257 times)

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
idHTTP (Indy10): hangs
« on: March 17, 2019, 08:53:20 am »
I have a separate worker thread that works with the network via idHTTP.
Working with a synchronous sockets, all the timeouts are set but occasionally somtimes the thread hangs forever [at the request stage that is idHTTP.Get]. Only restart helps.
Who solves this problem?
I want to emphasize that the temporary freezing of the thread is not a problem - it is a secondary thread, the problem is that the timeout seems to be infinite.

More nuances: I work with HTTPS via HTTPS proxy. Otherwise works well, if not for the occasional hang. Works under Linux in daemon app
Some peace of code:

Code: Pascal  [Select][+][-]
  1.  
  2.   FHTTPClient:=TIdHTTP.Create;
  3.   FIDSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  4.   FHTTPClient.IOHandler:=FIDSSL;
  5.   FIDSSL.ConnectTimeout:=10000;
  6.   FIDSSL.ReadTimeout:=16000;
  7.   FHTTPClient.ReadTimeout:=16000;
  8.   FHTTPClient.ConnectTimeout:=10000;
  9.   FHTTPClient.Socket.ReadTimeout:=20000;
  10.   FHTTPClient.Socket.ConnectTimeout:=10000;  
  11.  
  12. ... ... ...
  13.     Result:=FHTTPClient.Get(AUrl);
  14.  
  15.  
« Last Edit: March 17, 2019, 09:01:18 am by Renat.Su »

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: idHTTP (Indy10): hangs
« Reply #1 on: March 19, 2019, 05:30:08 pm »
Working with a synchronous sockets, all the timeouts are set but occasionally somtimes the thread hangs forever [at the request stage that is idHTTP.Get]. Only restart helps.
Who solves this problem?

There is no way to diagnose this without more information.  What URL are you accessing?  Is the freeze happening when sending the request, or when reading the response?  What does the actual HTTP traffic look like?  Do you have a reproducible case you can share to verify this?

I want to emphasize that the temporary freezing of the thread is not a problem - it is a secondary thread, the problem is that the timeout seems to be infinite.

Indy does use infinite timeouts by default, but you are overwriting them, so they should be working.

I will say that in some VERY RARE cases, I have seen Winsock's select() function freeze indefinitely even though data was available and a timeout was used, but that was an OS issue, not a Indy issue.  Doubtful that is what you are encountering, but I'm just throwing that out here.

More nuances: I work with HTTPS via HTTPS proxy. Otherwise works well, if not for the occasional hang.

Are you getting the hang while connected to the proxy?  At what stage during the proxy operations does the hang happen?

Some peace of code:

So, it is not even your code that is freezing, it is someone else's code?

Code: Pascal  [Select][+][-]
  1.  
  2.   FIDSSL.ConnectTimeout:=10000;
  3.   FIDSSL.ReadTimeout:=16000;
  4.   ...
  5.   FHTTPClient.Socket.ReadTimeout:=20000;
  6.   FHTTPClient.Socket.ConnectTimeout:=10000;  
  7.  

All of those assignments are redundant and should be removed.  The Socket property points at the SSL object, so the same properties are being set twice.  And the inherited Connect() method will overwrite them anyway with values from the client object.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
Re: idHTTP (Indy10): hangs
« Reply #2 on: March 22, 2019, 05:16:32 pm »
Sorry, just noticed the answer
There is no way to diagnose this without more information.  What URL are you accessing?
Various pages of Instagram via HTTPS
Quote
  Is the freeze happening when sending the request, or when reading the response?
Honestly haven't checked
Quote
What does the actual HTTP traffic look like?  Do you have a reproducible case you can share to verify this?
This can be a regular web page, and can be a JSON response from the same instagram web site (API end point).
All this works on the Linux web server. The bug appears only if it works through a proxy. This happens with some proxies that apparently sometimes may not respond . If you remove them, the problem ceases to be.
Quote
Indy does use infinite timeouts by default, but you are overwriting them, so they should be working.
I so think, so in confusion
Quote
I will say that in some VERY RARE cases, I have seen Winsock's select() function freeze indefinitely even though data was available and a timeout was used, but that was an OS issue, not a Indy issue.  Doubtful that is what you are encountering, but I'm just throwing that out here.
This usually happens rarely. But since I had to go requests to Instagram every second or every often that such an event eventually occurs, if there are bad proxies and the thread hangs ((
« Last Edit: March 22, 2019, 05:19:19 pm by Renat.Su »

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
Re: idHTTP (Indy10): hangs
« Reply #3 on: March 22, 2019, 05:28:42 pm »
Quote
Are you getting the hang while connected to the proxy?  At what stage during the proxy operations does the hang happen?
Probably a proxy. If no proxy then had no problems
Quote
So, it is not even your code that is freezing, it is someone else's code?
Did not quite understand the question. The code under the link is my
Quote
All of those assignments are redundant and should be removed.  The Socket property points at the SSL object, so the same properties are being set twice.  And the inherited Connect() method will overwrite them anyway with values from the client object.
Thanks. For a socket I set up timeouts already then, trying to solve a problem

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
Re: idHTTP (Indy10): hangs
« Reply #4 on: March 24, 2019, 08:09:53 am »
I used a hack, although I did not correct the reason. From another thread I check if the idHTTP client is hung up and if it is frozen send disconnect to it directly from another thread  ::)
Code: Pascal  [Select][+][-]
  1.         { Check that the idHTTP client is frozen }
  2.         if (Now-WorkersHandler.TimeoutChecker)>(1/MinsPerDay * 10) then
  3.         begin
  4.           Logger.Error('HTTP Client is frozen. Try to disconnect');
  5.           WorkersHandler.DisconnectidHTTP;
  6.         end;
  7.  
And it helps. The idHTTP client comes out of hibernation

 

TinyPortal © 2005-2018