+ Start a Discussion

httprequests timing out from specific SF org

I have been using Apex to do an httprequest to a specific website. All it does is a form post to a page. I have found that about 10% of the time, it fails with a "System.CalloutException: Read timed out" error. I've been testing this in the developer console.
I also have access to a separate Salesforce org, and I have run the exact same tests from there, and it has never gotten the Read Timed Out error.

I even wrapped the request in a try statement, and it will re-attempt if it fails the first time, but the second attempt fails 100% of the time.

I am wondering why one Salesforce org would be experiencing the issue whereas another one doesn't. The one having issues is on na5.

The code I am testing with is as follows, but I have replaced the website URL as I don't really want to post it publically, but the page is very simple and typically returns instantly, even if you post garbage content.
    HttpRequest req = new HttpRequest(); 
	integer debug=0;
	Map<String,String> headers = new Map<String, String>{};
	String method = 'POST';
	String body='cmd=test';
	if(method == 'POST') { 
		system.debug('content-type is >' +headers.get('content-type'));
		req.setHeader('content-type', headers.get('content-type') );

		req.setCompressed(false); // otherwise we hit a limit of 32000


	if ( ! headers.isEmpty() ) { 
		for(string k:headers.keySet() ) { 
			system.debug('setheader ' + k + ' => ' +headers.get(k) ); 
			req.setHeader(k, headers.get(k) ); 

	Http http = new Http();
	HttpResponse res;

	String resultString;
	String resToString;
	String resBody;
	String resStatus;
	Integer resStatusCode=0;
	try {
		res = http.send(req);
	} catch(System.CalloutException e) {
		system.debug('Error...will retry');
    		res = http.send(req);
	resStatusCode = res.getStatusCode();
	resStatus = res.getStatus();
	resultString = resBody;
	System.debug(resStatusCode) ;

Does anyone have any idea why a certain SF org might experience sporadic time outs?
Thanks for any help.

James LoghryJames Loghry
Hi Ako, servers can vary from time to time in their performance.  Any number of factors can slow a pod down, and it's always a good idea to check http://trust.salesforce.com/status when it comes to Salesforce's pods.

Typically some pods are slower than others, but it's difficult to work around that.  The best you can do is keep your services, interactions, integrations as light weight as possible, and implement the best error handling (and perhaps retry / queueing logic) you can.

Hope that helps.