简体   繁体   中英

Jmeter: TCP Sampler error: 500 ReadException: Error reading from server, bytes read: 0

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM