Author Topic: Synapes v40 .Timeout misbehaving  (Read 2077 times)


  • Sr. Member
  • ****
  • Posts: 435
Synapes v40 .Timeout misbehaving
« on: February 21, 2018, 05:47:10 am »
I'm trying to get my HTTPSend to not wait so long for an answer.  It is waiting 12 seconds, and I would like it to wait a user defined number of seconds... preferably only 3 seconds.

Here is my code:

        HTTPSender := THTTPSend.Create;
        HTTPSender.Timeout := UserTimeoutSettingInSeconds * 1000;
        HTTPGetResult := HTTPSender.HTTPMethod('GET', URL);

Regardless of what I set UserTimeoutSettingInSeconds to 1 or 5 or 8, it always waits at least 15 seconds for an answer.

I read this post about v40 from a while back, and I was wondering... what are the correct steps to take, and code to change, to fix this problem to get HTTPSend to obey my user's timeout setting?,32037.msg206126.html#msg206126

I'm on Lazarus 1.8.1, FPC 3.0.5, Synapes 40


  • Hero Member
  • *****
  • Posts: 5125
Re: Synapes v40 .Timeout misbehaving
« Reply #1 on: February 21, 2018, 09:37:21 am »
I take it you are talking about non-responsive sites and not for normal sites?

Anyway, your problem is not the TimeOut during communications (which you can tweak with TimeOut) but with the "Connect Timeout". Synapse says this about it:

These timeouts are not for Connect. Connect timeout is hardcoded in your socket provider. This timeout is for sending or receiving datas and your socket provider must know it.
How To Change Connect Timeout

Synapse library using sockets in blocking mode. But blocking call of Connect not have any timeout. Timeout for Connect is hardcoded in communication stack of your operating system.

:!: Any timeout property in Synapse cannot define timeout for connecting of TCP channel. It is not a bug, it depending on design of used socket API.

Exists two possible workarounds:

Call Connect in non-blocking mode. (ugly…)
Raise helper thread and after timeout try to close socket handler from this thread. (it is ugly too…)

So it seems the only way to do this is to implement some threading.


  • Hero Member
  • *****
  • Posts: 5125
Re: Synapes v40 .Timeout misbehaving
« Reply #2 on: February 21, 2018, 09:48:45 am »
Sorry, I spoke too soon. What is said above still holds but the connect timeout was discussed on the Synapse list in 2012 and the non-blockingmode (which is mentioned above) was implemented in revision #160.

You also need to set the HTTPSender.Sock.ConnectionTimeout which handles the Connect timeout in non-blockingmode after which the socket is switched back to blocking mode.

Code: Pascal  [Select][+][-]
  1. const
  2.   URL = ''; // <-- this is always non response
  3. var
  4.   HTTPSender: THTTPSend;
  5.   HTTPGetResult: boolean;
  6.   Tm: TDateTime;
  7. begin
  8.   HTTPSender := THTTPSend.Create;
  9.   try
  10.     HTTPSender.Timeout := 1 * 1000;
  11.     HTTPSender.Sock.ConnectionTimeout := 1 * 1000;
  12.     Tm := Now;
  13.     HTTPGetResult := HTTPSender.HTTPMethod('GET', URL);
  14.     Tm := Now - Tm;
  15.     ShowMessage(Format('%d: done in %.3f seconds', [HTTPSender.ResultCode, Tm * 24 * 60 * 60]));
  16.   finally
  17.     HTTPSender.Free;
  18.   end;
  19. end;


TinyPortal © 2005-2018