SAP Knowledge Base Article - Public

3005504 - CPI Runtime Error: HTTP Request failed with error: Connection refused.

Symptom

Integration flows fail intermittently at runtime with exception comparable to the below examples.

  • com.sap.it.rt.adapter.http.api.exception.HttpResponseException: An internal server error occured: HTTP Request failed with error : Connection to https://my000000-api.s4hana.ondemand.com refused.
  • com.sap.gateway.core.ip.component.odata.exception.OsciException: Connection to https://my00000-api.s4hana.ondemand.com refused.

Reproducing the Issue

Multiple requests are made within a short span of time to the same endpoint. In the above example the endpoint is https://my00000-api.s4hana.ondemand.com

Cause

The issue occurs when there are no connections available at the server to execute the request. There are multiple reasons for the issue to occur. One of the likely causes is non-closure of connection from the client. This behavior can be effectively managed by using "Connection" header in the request. You can read more about the Connection header in the HTTP specifications - https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.10.

In SAP Cloud Platform Integration, few adapters such as the OData V2 neither sends the connection header nor reuses the connection. Hence they are safely closed.

The absence of connection header can lead the server to keep the connections live until timeout. In cases of too many requests in a short span, the server can run out of connections resuting in the connection refused error.

Resolution

The following steps show how the "Connection" header can be added to the OData adapter.

  • Add a Content Modifier and create a header entry with name "Connection" and value "Close" as seen below.
  1. MicrosoftTeams-image (9).png
  • In the OData adapter, add "Connection" header to the allowed list of Request Headers as seen below. Similarly, include the entry in the Metadata section. In case you do not see the below configuration in your adapter, it is likely that you're using an older version of the adapter. Delete the older version and add the latest version of the OData adapter.
  • MicrosoftTeams-image (8).png

Keywords

KBA , LOD-HCI-PI-CON-OD , CPI OData Adapters , Problem

Product

SAP S/4HANA Cloud 2008