Hello,
I am using Lazarus 2.0.7, SVN rev: 62300 from fixes 2.0 branch. fpc version is 3.2.0 SVN rev: 43667 from fixes 3.2 branch. OS is Raspbian, Debian 10.2 with all updates installed.
I have below function that I frequently call.
function CallRestService(const URL: string; const Data: RawUTF8; out Response: string): Boolean;
var
Http: TFPHTTPClient;
MS: TMemoryStream;
ServerResponse: TMemoryStream;
SS: TStringStream;
begin
Log('REST: Calling URL: ' + URL);
Log('REST Request: ' + string(Data));
Http := nil;
MS := nil;
ServerResponse := nil;
SS := nil;
try
MS := TMemoryStream.Create();
MS.Write(Pointer(Data)^, Length(Data));
MS.Position := 0;
ServerResponse := TMemoryStream.Create();
Http := TFPHTTPClient.Create(nil);
Http.RequestHeaders.Values['Content-Type'] := 'application/json';
Http.RequestHeaders.Values['UserAgent'] := EmptyStr;
Http.ConnectTimeout := 60 * 1000;
Http.IOTimeout := 60 * 1000;
if UseProxy then
begin
Http.Proxy.Host := 'localhost';
Http.Proxy.Port := 8888;
end
else
begin
Http.Proxy.Host := EmptyStr;
Http.Proxy.Port := 0;
end;
try
Http.RequestBody := MS;
Http.Post(URL, ServerResponse); // <--- EXCEPTION HERE
except
on E: Exception do
begin
Log('CallRestService()-Http.Post(): ' + StringReplace(E.Message, sLineBreak, ' ', [rfReplaceAll]));
Exit(False);
end;
end;
SS := TStringStream.Create(EmptyStr, TEncoding.UTF8);
ServerResponse.Position := 0;
SS.LoadFromStream(ServerResponse);
Response := SS.DataString;
Log('REST Response: ' + Response);
Result := True;
finally
SS.Free();
ServerResponse.Free();
MS.Free();
Http.Free();
end;
end;
When application is running without debug mode, my second call to it raises exception "Project raised exception class 'ESocketError' with message: Connect to <domain>:443 failed". My call times in log is as following:
1- 2019-12-12 18:14:14.874
2- 2019-12-12 18:14:16.540
However, if I am to run application in debug mode, put a break point on marked line in above code and hit F9 when code stops then everything goes smooth. No exception, no error. My function call times in debug run are as following:
1- 2019-12-12 18:23:41.796
2- 2019-12-12 18:23:47.452
3- 2019-12-12 18:23:51.208
4- 2019-12-12 18:23:53.944
5- 2019-12-12 18:23:56.544
6- 2019-12-12 18:23:58.496
7- 2019-12-12 18:24:00.911
All calls are to same exact domain from first to last. All calls are using HTTPS protocol.
I failed to see what I am doing wrong and searching for help, please.
Thanks & regards,
Ertan