Karbot 0 Posted March 3, 2022 Hello folks, We're having an issue with local requests. They take much longer than external API calls. It's just a simple GET to the API and it's not reproducible with any other RestClient written with C# or Python. PASCAL/Delphi is not my native language, so I hope to find help here. Please see the timing behavior and code used below. Kind Regards karbot https://<external_hostname> (26ms) https://<external_ip> (168ms) https://mypc (6049ms) https://192.168.178.102 (24ms) https://localhost (2029ms) https://127.0.0.1 (26ms) function TAPIConnector.SendApiRequest(const aURL, aOperation: string; aSetApiParams: TProc<TRESTRequest>; aRaiseException: Boolean): TRESTResponse; begin var restClient := TRESTClient.Create(aURL); try restClient.RaiseExceptionOn500 := aRaiseException; var restRequest := TRESTRequest.Create(restClient); restRequest.Client := restClient; restRequest.Method := TRESTRequestMethod.rmPOST; restRequest.Resource := aOperation; if (Assigned(aSetApiParams)) then begin aSetApiParams(restRequest); end; Result := TRESTResponse.Create(nil); try restRequest.Response := Result; restRequest.Execute; if aRaiseException and not Result.Status.Success then begin const cInvalidSession = 'No valid session GUID'; if Result.Status.ClientErrorUnauthorized_401 and Result.StatusText.Contains(cInvalidSession) then begin raise Exception.Create(aOperation); end; var msg := Result.ErrorMessage; if msg.IsEmpty then begin msg := Result.StatusText; end; raise Exception.Create(aOperation + msg); end; except Result.Free(); raise; end; finally restClient.Free; end; end; Share this post Link to post
Guest Posted March 3, 2022 There must be loads of net/http OS libs. Try another one in the same project (the beauty of Delphi). My rec would be to try out rtc.teepi.net (trial - it is ridiculously stable) but that is only one. ICS also. And so on... Share this post Link to post
Der schöne Günther 316 Posted March 4, 2022 (edited) I remember also having this! localhost first ran into a 2000 ms timeout, but 127.0.0.1 was normal. After we made our local server listen for ipv6 connections as well, that timeout was gone. Edited March 4, 2022 by Der schöne Günther Share this post Link to post
Angus Robertson 574 Posted March 4, 2022 Quote After we made our local server listen for ipv6 connections as well, that timeout was gone. Yes, I've seen that. If the client is allowed to use IPv6 and IPv4, it will try IPv6 first, timeout and try IPv4. All client software should have a setting to make it use IPv4 only, in ICS it's SocketFamily. Angus Share this post Link to post
Angus Robertson 574 Posted March 4, 2022 To clarify, this is down to DNS. If a DNS lookup returns both IPv4 and IPv6 addresses, the client will usually try IPv6 first. The Windows HOSTS file has both IPv4 and IPv6 lookups for localhost so servers need to listen on both addresses. Can be fixed by removing the IPv6 address from HOSTS. Angus Share this post Link to post
Karbot 0 Posted March 4, 2022 (edited) Many thanks to your answers. I will investigate them. The IPv6 approach seems pretty logical to me. I will have a look at that first and let you know. Maybe there is a switch in the rest libary to set the SocketFamily. Regards Karbot Edited March 4, 2022 by Karbot Share this post Link to post
Karbot 0 Posted March 4, 2022 2 hours ago, yonojoy said: How fast is ping -4 mypc ? It's <1ms but it is using ipv6. Another pointer in that direction. Thanks Share this post Link to post
yonojoy 2 Posted March 4, 2022 (edited) 7 hours ago, yonojoy said: How fast is ping -4 mypc ? 5 hours ago, Karbot said: It's <1ms but it is using ipv6. Another pointer in that direction. Thanks No. If you apply the -4 switch usage of ipv4 should be forced (in Windows). Edited March 4, 2022 by yonojoy Share this post Link to post