Custom API Timeout Issues Due to High Session Wait Time in ServiceNow Integration

scarcher
Giga Contributor

Hello fellow developers,

 

I'm experiencing an issue with a custom API we've developed, which is integrated with ServiceNow. We're facing timeout issues and have identified that the cause is a high "Session Wait Time" during API requests.


Our requests to the custom API generally take between 2-10 seconds to complete. However, when we try to call our Web Service in ServiceNow, we encounter timeouts. Analyzing the transaction logs, we've observed up to 300 seconds of session wait time, which seems to be causing the problem.


I was wondering if anyone has experience with this issue and could provide some guidance on the following questions:

  1. Is there a way to disable session wait time for an API user account in ServiceNow?
  2. If not, is it possible to increase the session wait time limit to avoid our requests stacking up and timing out?
  3. Are there alternative approaches or best practices we should consider to avoid these types of performance issues in our custom API and ServiceNow integration?

Any insights, suggestions, or resources on this matter would be greatly appreciated. We're eager to find a solution to this problem and improve the performance of our custom API.

 

Thank you in advance for your assistance.

Best regards,

 

Scott



 

1 ACCEPTED SOLUTION

scarcher
Giga Contributor

We were using dotnet 7 to call the API in ServiceNow. The HttpClient in dotnet 7 persists cookies between calls by default, this resulted in us reusing the same ServiceNow session for all of our API Calls. Since each session is only allowed one request at a time, this resulted in the "session wait" times and eventual timeouts.

We were able to resolve the issue by disabling cookies in the dotnet HTTP Client which stopped the session reuse.

https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler.usecookies?view=net-8...

View solution in original post

5 REPLIES 5

Hayo Lubbers
Kilo Sage

Hi @scarcher ,

 

If a direct call to the custom API is in 2-10 seconds and ServiceNow has a timeout after 5min, extending the timeout doesn't sound like the logical way forward.

 

Try to pinpoint the cause of the delay. This might be a firewall or network issue between the ServiceNow and API endpoint.

If it is going over a MID Server, is the MID Server very busy? Can you traceroute the endpoint from the MID Server and is that fast or also slow?

 

Is it via Flow Designer or Script? I once had an integration where the Flow Designer ran into a timeout (for only 1800 records), but scripted would finish within 20seconds.

 

The wait time can be extended (in both script as well as flow designer), but that is trying to patch another problem and doesn't solve the issue itself. If you still think that is a good idea:

- setHttpTimeout : https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/sn_ws-namespace/c_RESTMessageV2...

- connection timeout : https://docs.servicenow.com/bundle/sandiego-application-development/page/administer/flow-designer/re...

 

Hope this helps.

 

I'm not experiencing issues calling an API from ServiceNow, I'm experiencing timeouts when calling an API developed / exposed by ServiceNow.

 

There are no mid-servers involved as the call is directly to the ServiceNow API.

This is an "Inbound Integration" using "Scripted REST APIs" and "Scripted REST Resources" in ServiceNow.

We're basically calling a simplified API to raise a ticket passing only a subset of necessary data and then creating the ticket within the scripted REST API.

 

The problem is the "Session Wait Time" in ServiceNow.

Are you having very difficult queries or a large set of data?

Have a look at the debugging options for the (scripted) rest api, maybe it helps in pinpointing the issue : https://docs.servicenow.com/bundle/utah-api-reference/page/integrate/inbound-rest/concept/debugging-...

 

scarcher
Giga Contributor

We were using dotnet 7 to call the API in ServiceNow. The HttpClient in dotnet 7 persists cookies between calls by default, this resulted in us reusing the same ServiceNow session for all of our API Calls. Since each session is only allowed one request at a time, this resulted in the "session wait" times and eventual timeouts.

We were able to resolve the issue by disabling cookies in the dotnet HTTP Client which stopped the session reuse.

https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler.usecookies?view=net-8...