You need to sign in to do that
Don't have an account?
Brett Phillips 9
Repeated Read timed out on HttpRequest
I have a puzzling issue that I cannot figure out. I have a very simple REST service running on an external server returning a small JSON response for every GET request. It is set up as a simple service to verify I can connect to it from Salesforce. This service returns without issue when hit from a browser, CURL, etc. However, when we try from Salesforce, it takes a number of tries to get a return. Here is the simple Apex code I've wrote the check the service:
When running this section of code, there are a number of times "Read timed out" happens when making the HttpResponse call before a successful response is received. Here are a couple examples of an output from the logs:
As you can see, there is no reason or frequency for the timeouts. I have control over the server that is accepting the requests but unfortuantely I do not have control over the network level firewall. I have been told there are no restrictions to the network for any and all traffic. That seems to be the case because calls can be made from everywhere with issues. On the server logs, I see a successful request coming in but do not see any requests when there is a timeout.
Is there anything from the Salesforce side that could be causing this issue? I want to make sure I cover all possible points in this process that could be causing this failure.
Http h = new Http(); HttpRequest req = new HttpRequest(); String url = '<webservice being called>'; req.setEndpoint(url); req.setMethod('GET'); HttpResponse res; while(res == null){ try{ res = h.send(req); System.debug(res.getBody()); } catch(CalloutException e) { System.debug(e.getMessage()); } }
When running this section of code, there are a number of times "Read timed out" happens when making the HttpResponse call before a successful response is received. Here are a couple examples of an output from the logs:
As you can see, there is no reason or frequency for the timeouts. I have control over the server that is accepting the requests but unfortuantely I do not have control over the network level firewall. I have been told there are no restrictions to the network for any and all traffic. That seems to be the case because calls can be made from everywhere with issues. On the server logs, I see a successful request coming in but do not see any requests when there is a timeout.
Is there anything from the Salesforce side that could be causing this issue? I want to make sure I cover all possible points in this process that could be causing this failure.
Check out the setTimeout method. Note that the default timeout is 10 seconds, as detailed here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_timeouts.htm
I would also remove your callout from that while loop; as with DML and queries, it's not a good practice to make an HttpRequest inside of a loop.
I have used the setTimeout method. I've tried 60 seconds, 15 seconds, 2 seconds, etc (all calculated to milliseconds for the setTimeout method) and get the same results, to remove that as an issue.
Oh I completely agree - this is terrible practice but I'm just using this to debug this and make sure Salesforce can actually connect to this service at some point. Once I can establish a reliable, stable connection, I will use good practices :)
We face same issue. First calls usually fail fast with read timeout.
Have you managed to address this issue?
Even if we set timeout to 15-20seconds it fails much faster.
We have tried calls with postman/curl and we get response after 2-3 seconds.
It seems that setTimeout is ignored (by the way there is no way to check set value since there is no getter).
Best
Kostas