1

I'm running some test cases from outside of container by calling endpoints of the container (localhost:8087)

I'm using apache httpclient to call locally running container but I keep getting connection reset error. Now, it works fine on my local machine, but when I'm running in pipeline, it fails. The containers are getting created properly in pipeline yet when the tests are running, I keep getting this error.

I've tried setting connection and socket timeouts too. Didn't help.

Sample code (getting exception in last line) -

    private static final CloseableHttpClient httpClient = 
    HttpClients.createDefault();
    HttpGet request = new HttpGet("http://localhost:8087/health");
    CloseableHttpResponse response = httpClient.execute(request);

Stacktrace:

java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:210) at java.net.SocketInputStream.read(SocketInputStream.java:141) at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137) at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153) at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259) at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163) at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:157) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)

N.Rajal
  • 105
  • 2
  • 17
  • 1
    This can help https://stackoverflow.com/questions/62929/java-net-socketexception-connection-reset – Arthur Klezovich Nov 08 '21 at 16:59
  • 2
    "Connection reset" essentially means "somebody pulled the plug". Check your internet connection to the server. Check the server's system and Apache error logs. If there's a proxy server in the mix, check that, too. Please read this: [How to Fix with java.net.SocketException: Connection reset Exception in Java?](https://www.java67.com/2020/05/how-to-deal-with-javanetsocketexception-connection-reset-client-server-error.html) – paulsm4 Nov 08 '21 at 17:00
  • As the application is running in a container, I can't get the error logs directly. And I also don't have the access to the system where my containers are created. @paulsm4 I've checked out the article, I added ```CloseableHttpClient close``` call using @AfterAll and also closing http request after every test using ```request.releaseConnection()```. I'm not sure what else is it that I'm missing, despite of the fact that it works fine on my local inside a container. – N.Rajal Nov 09 '21 at 08:03
  • Did you solve this problem? I'm having the same problem as you. If you've solved this problem, I'd like some help. – Hyeonil Jeong Dec 28 '22 at 01:27

0 Answers0