4

While checking TCP connection from Jmeter TCP Sampler, we are getting below error:

Response code: 500
Response message: org.apache.jmeter.protocol.tcp.sampler.ReadException: Error reading from server, bytes read: 0

We tried changing EOL, Connect & Response timeouts, Re-use connection & Close connection settings, but no luck.

Jmeter TCP Sampler log:

2018-04-24 12:09:09,740 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2018-04-24 12:09:09,741 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2018-04-24 12:09:09,745 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2018-04-24 12:09:09,755 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : DS Requests
2018-04-24 12:09:09,756 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group DS Requests.
2018-04-24 12:09:09,764 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2018-04-24 12:09:09,765 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=5 perThread=5000.0 delayedStart=false
2018-04-24 12:09:09,765 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2018-04-24 12:09:09,765 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2018-04-24 12:09:09,766 INFO o.a.j.t.JMeterThread: Thread started: DS Requests 1-1
2018-04-24 12:09:09,767 INFO o.a.j.p.t.s.TCPClientImpl: Using platform default charset:windows-1252
2018-04-24 12:09:09,767 INFO o.a.j.p.t.s.TCPSampler: Using eolByte=10
2018-04-24 12:09:09,787 ERROR o.a.j.p.t.s.TCPSampler: 
org.apache.jmeter.protocol.tcp.sampler.ReadException: Error reading from server, bytes read: 0
    at org.apache.jmeter.protocol.tcp.sampler.TCPClientImpl.read(TCPClientImpl.java:131) ~[ApacheJMeter_tcp.jar:3.3 r1808647]
    at org.apache.jmeter.protocol.tcp.sampler.TCPSampler.sample(TCPSampler.java:403) [ApacheJMeter_tcp.jar:3.3 r1808647]
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:498) [ApacheJMeter_core.jar:3.3 r1808647]
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:424) [ApacheJMeter_core.jar:3.3 r1808647]
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:255) [ApacheJMeter_core.jar:3.3 r1808647]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_144]
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source) ~[?:1.8.0_144]
    at java.net.SocketInputStream.read(Unknown Source) ~[?:1.8.0_144]
    at java.net.SocketInputStream.read(Unknown Source) ~[?:1.8.0_144]
    at org.apache.jmeter.protocol.tcp.sampler.TCPClientImpl.read(TCPClientImpl.java:114) ~[ApacheJMeter_tcp.jar:3.3 r1808647]
    ... 5 more
2018-04-24 12:09:09,788 INFO o.a.j.t.JMeterThread: Thread is done: DS Requests 1-1
2018-04-24 12:09:09,788 INFO o.a.j.t.JMeterThread: Thread finished: DS Requests 1-1
2018-04-24 12:09:09,789 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2018-04-24 12:09:09,789 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

Please suggest how to fix this issue.

Kiran Maroju
  • 148
  • 1
  • 12
  • How many users/threads you used? From this I suspect Its not issue from JMeter side. looks like you need to check server logs for errors. Also check when server can throw such error https://stackoverflow.com/questions/30745350/why-am-i-receiving-response-code-non-http-response-code-java-net-socketexcepti/30747112#30747112 – Nachiket Kate Apr 24 '18 at 11:29
  • 1
    if this happens even for one user, then something that you send is wrong; server does not like it and does not have a graceful handling of the errors in this case. If it happens after some number of users, then you maybe running out of some resources (ports?) on server – Kiril S. Apr 24 '18 at 17:01
  • It is happening for 1 user as well. – Kiran Maroju Apr 26 '18 at 10:38

1 Answers1

2

Checking connectivity using TCP Sampler is not the best idea, I would recommend going for JSR223 Sampler and Socket class instead:

def sock = new Socket()
def host = "example.com" // change it to your host
def port = 80 // change it to your port
def timeout = 1000 // change it to your timeout (in milliseconds)
sock.setSoTimeout(1000)
sock.connect(new InetSocketAddress(host, port))

if (sock.isConnected()) {
    log.info('Connection established')
    SampleResult.setSuccessful(true)
}
else {
    log.info('Server is not listening')
    SampleResult.setSuccessful(false)
}

See Apache Groovy - Why and How You Should Use It article for more information on enhancing your JMeter test with Groovy scripting.


In the majority of cases it is much easier to use HTTP Raw Request plugin than the TCP Sampler.

Dmitri T
  • 119,313
  • 3
  • 56
  • 104
  • Thanks Dmitri, connection test is fine now with JSR223. I need to check TCP request also by sending some xml content and check for the response from the server as well. Could you please help me that also. – Kiran Maroju Apr 24 '18 at 14:59