Synchronous Outbound Web Service Calls Timing Out After 2 min
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2023 08:52 PM - edited ‎09-28-2023 08:53 PM
Hi
I have a REST message using an HTTP POST request. It's an application used to retrieve data, and sometimes it takes more than 2 minutes to respond with the data. Even though the target instance has not responded, we receive either blank responses or socket errors in such cases. I've attempted to set the setHttpTimeout() both 3 minutes and 5 minutes, but it still fails. It appears that the API is only waiting for a response for 2 minutes.
var body = '{"product_num":"PROD20106","source": "PROD"}';
var r = new sn_ws.RESTMessageV2();
r.setEndpoint('endpoint');
r.setHttpMethod('POST');
r.setHttpTimeout('180000');
r.setRequestHeader("Authorization", 'Basic authentication');
r.setRequestHeader("x-api-key", "key here");
r.setRequestHeader("Content-Type", "application/json");
r.setRequestBody(body);
r.setHttpTimeout(180000);
var response = r.execute();
//response.waitForResponse(90);
var statusCode = response.getStatusCode();
if (statusCode === 200) {
var responseBody = JSON.parse(response.getBody());
gs.info("SRI Response statusCode: " + statusCode);
} else {
var err = 'Could not retrieve data - Request failed with code ' + statusCode;
gs.info("SRI Error: " + err);
}
I get outputs as
x_snc_price_master: START execution: 2023-09-28 01:59:33 {"product_num":"PROD20106","source": "PROD"} x_snc_price_master: Before REST request execution: 2023-09-28 01:59:33 {"product_num":"PROD20106","source": "PROD"} Socket error: Connection reset x_snc_price_master: Error: Could not retrieve data - Request failed with code 0 x_snc_price_master: After REST request execution: 2023-09-28 02:01:33 {"product_num":"PROD20106","source": "PROD"}
Tried with executeAsync() as well. Tried to modify the below properties as well.
'glide.http.outbound.max_timeout.enabled' to True
glide.http.outbound.max_timeout = 600000
glide.http.timeout' to '1750000'
'glide.http.connection_timeout' to '1000000'.
Also, I tried to configure the REST message and tested by hitting "TEST" which is OUT OF THE BOX rest message test feature. It is still failing at 2 mins. The API flaps exactly at 2 mins, and tried running the code in BS, in scoped/global its the same issue.
Any help on this in much appreciated.
Thanks
Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2023 03:31 AM
@srivatsa_tatti I tried to simulate the timing out in my 2 PDIs they are working fine, we should look for something else in the instance.
Have you tried testing with any other API? If not try creating a TEST Scripted API in any of your sub prod instances, with the following code and call that API from the problematic Instance.
var time = 180000;
var t1 = new GlideDateTime().getNumericValue();
var t2 = new GlideDateTime().getNumericValue();
var duration = t2 - t1;
while(duration < time){
t2 = new GlideDateTime().getNumericValue();
duration = t2 - t1;
}
return 'true';
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2023 06:48 AM - edited ‎09-29-2023 12:34 PM
HI @AnveshKumar M ,
Thanks for reply, i did try to create a TEST script api and called from problematic instance it worked as expected. But here Source and Target it ServiceNow instance. But in actual scenario Source is ServiceNow and Target is Boomi. We also have increase time out at target to 10mins. So responses are being sent back from the target instance. Looks like client Servicenow is cutting off.
But i tried the actual call from POSTMAN it works and i get response in 2.54 mins, but from servicenow it flaps out at exactly 2.00.XX mins
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2023 07:13 AM
@srivatsa_tatti Are you using the Direct end point or is there any API gateway kind of thing?
I have a strong feeling that, the issue is not with ServiceNow side.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2023 07:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2023 07:35 AM
@srivatsa_tatti after looking at the POSTMAN screenshot, what I understood is ServiceNow received data which it can not handle and causing the SOCKET Failure - Connection Reset.
How much amount of data your API is returning?
Anvesh