How to resolve occasional "java.net.SocketException: Connection reset" exception with "Invoke REST API" activity
book
Article ID: KB0073662
calendar_today
Updated On:
Products
Versions
TIBCO ActiveMatrix BusinessWorks Plug-in for REST and JSON
2.0.0, 2.0.1, 2.1.0
Description
Some customers might encounter occasional "java.net.SocketException: Connection reset" error when invoking 3rd party REST Server with Invoke REST API activity, most of the HTTP Request is working fine but some requests will get below error, especially after a certain time.
======= Activity invocation failed at com.tibco.pe.plugin.Activity.postEval(Unknown Source) at com.tibco.pe.plugin.Activity.postEval(Unknown Source) at com.tibco.pe.core.TaskImpl.eval(Unknown Source) at com.tibco.pe.core.Job.a(Unknown Source) at com.tibco.pe.core.Job.k(Unknown Source) at com.tibco.pe.core.JobDispatcher$JobCourier.a(Unknown Source) at com.tibco.pe.core.JobDispatcher$JobCourier.run(Unknown Source) caused by: javax.ws.rs.ProcessingException: java.net.SocketException: Connection reset at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:287) at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252) at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:701) at org.glassfish.jersey.internal.Errors.process(Errors.java:315) at org.glassfish.jersey.internal.Errors.process(Errors.java:297) at org.glassfish.jersey.internal.Errors.process(Errors.java:228) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444) at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:697) at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:448) at com.tibco.plugin.json.activities.RestActivity.sendReqeustWithBody(RestActivity.java:502) at com.tibco.plugin.json.activities.RestActivity.doPostAlike(RestActivity.java:482) =======
The "Connection reset" exception usually happens when the client tries to write more data on the stream after closing the socket, the reason for closing the socket might be related to a Server issue, network problem or firewall configure.
Environment
Operation Systems: All
Resolution
In HTTP 1.1, the "Invoke REST API" will use persistent HTTP connection by default, it will send HTTP Header "Connection: keep-alive" when sending the HTTP request, in this case, the HTTP connection will be kept alive, all request/response will use the same HTTP connection. The advantages of using a persistent HTTP connection are to reduce latency, CPU usage, or network congestion.
However sometimes, for example, the firewall will monitor all non-used connections, it will drop and close the non-used connections after a certain time, such as 2 hours. In this case, after several hours or days, the "Invoke REST API" will still try to use the same connection to send the request to the server which is already closed. Then customer might encounter the "Connection Reset" exception.
Customer can add HTTP Header "Connection: close" in HTTP Request, in this case, the connection will not be considered persistent, it will be closed after usage, every new request will create a new HTTP connection and the customer will not encounter "Connection Reset" exception. To Add the Header, the customer can go to "Input Editor" of Invoke REST API, add "Connection" under Header, and then go to "Input", specify "close" for "Connection" See attached screenshots for more information.
Customers can also check the firewall or Server setting to adjust the "keep-alive" time setting to avoid the issue.
Issue/Introduction
How to resolve occasional "java.net.SocketException: Connection reset" exception with "Invoke REST API" activity
Attachments
How to resolve occasional "java.net.SocketException: Connection reset" exception with "Invoke REST API" activityget_app
How to resolve occasional "java.net.SocketException: Connection reset" exception with "Invoke REST API" activityget_app