Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "java.io.IOException: An existing connection was forcibly closed by the remote host"

Tags:

java

rest

ibm-bpm

I am making rest call to IBM Cloud BPM. Some times calls are working fine.But sometimes it is giving following error.

java.io.IOException: An existing connection was forcibly closed by the remote host.

java.io.IOException: An existing connection was forcibly closed by the remote host
    at sun.nio.ch.SocketDispatcher.read0(Native Method)
    at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
    at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)

Can any one help me on how to solve this issue.

Any help is greatly appreciated.

like image 381
Rajesh Kohir Avatar asked Jun 13 '16 10:06

Rajesh Kohir


People also ask

How do I fix an existing connection was forcibly closed in Minecraft?

It's possible that the Java files someone uses to connect to the server are outdated. The error "An existing connection was forcibly closed" may be due to this. People need to check Java for updates, or they may even have to reinstall Java if it comes to that. Once that is done, retry joining the test server.

Why does it says an existing connection was forcibly closed by the remote host?

The error means the service is not running or the client cannot reach the remote system. You'll want to get the IP address (ipAddress) returned from your code to make sure the IP is the expected IP. While remoted into the server ping the remote IP address to see if the IP is reachable from your server.

What does internal exception Java IO IOException An existing connection was forcibly closed by remote host mean?

Internal Exception: java.io.IOException: An existing connection was forcibly closed by the remote host. This error can occur due to multiple reasons, and the solution will vary accordingly. The common reasons for the error include firewall blocking the connection, internet connection, and router issues.


2 Answers

I had this error when consuming my API from an outside PC, but when calling from the same PC it worked fine.

To fix to, I went to Control Panel
Right click in Java icon Go to Advanced Tab

Then check Enable Operating System's restricted environment Apply and Save

enter image description here

This fixed my problem.

like image 168
Roberto Rodriguez Avatar answered Sep 28 '22 11:09

Roberto Rodriguez


Such behavior could be explained if the HTTP Client you use opens persistent connections to the server, and the server occasionally terminates them.

Normally, the connection to an HTTP server is closed after each response. With HTTP "keep-alive" you keep the underlying TCP connection open until certain criteria are met. What those conditions are depends on the server, which is free to close the connection after an arbitrary timeout or number of requests (just as long as it returns the response to the current request).

When the server closes such a connection the client usually reopens it again, and depending on implementation, may throw an exception or print a warning.

For example, Vert.x HttpClient (which opens persistent connections by default) also throws...

java.io.IOException: An existing connection was forcibly closed by the remote host

...when the server terminates them.

like image 41
curd0 Avatar answered Sep 28 '22 11:09

curd0