All Products
Search
Document Center

Performance Testing:Resolve the java.net.SocketException: Socket closed error in the sampling log

Last Updated:Mar 10, 2026

Symptom

When you stress test an HTTPS API, response time (RT) gradually increases while transactions per second (TPS) and success rate drop to zero or trend toward zero. The sampling log reports the following error:

The following error message appears in the sampling log:

java.net.SocketException: Socket closed
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:542)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:414)
at org.apache.jmeter.protocol.http.sampler.LazySchemeSocketFactory.connectSocket(LazySchemeSocketFactory.java:97)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
at org.apache.jmeter.protocol.http.sampler.hc.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:318)
at org.apache.jmeter.protocol.http.sampler.MeasuringConnectionManager$MeasuredConnection.open(MeasuringConnectionManager.java:114)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.executeRequest(HTTPHC4Impl.java:695)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:454)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1189)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1178)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:498)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:424)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:255)
at java.lang.Thread.run(Thread.java:766)

The Timing Waterfall in the sampling log confirms that all time is spent during the connection establishment phase.

Cause

In most cases, this error occurs because no connection timeout period is configured.

Solution

Confirm that KeepAlive is enabled

On the Basic tab of the HTTP request sampler, verify that Use KeepAlive is selected.

Configure the connection timeout

On the Advanced tab of the HTTP request sampler, configure the following parameters:

  1. Set Implementation to HttpClient4.

  2. Set Connect to a value between 10 and 60 seconds as the idle connection timeout period. This prevents the connection from being disconnected due to the failure to receive the Keep-Alive header returned by the stress testing server.

Advanced tab configuration

Verify the fix

After you apply the configuration, run a short stress test with reduced concurrency. Check the sampling log to confirm that:

  • The java.net.SocketException: Socket closed error no longer appears.

  • The Timing Waterfall no longer shows excessive time in the connection establishment phase.

  • RT, TPS, and success rate remain stable throughout the test.

References