2

I'm developing a JMeter script for an ajax dashboard. The user logs in, navigates to a repository, clicks on the dashboard link, waits for the dashboard to display, and then logs out.

The dashboard has five dashlets. I've come to a point in the script where there are five pairs of samplers, one for each dashlet. The first sampler in each pair has a POST REST request with with ajax in the body. There is a regular expression extractor that extracts an id from the body of the response. This id is added to the URL in the second sampler of the pair, which also has a POST REST request with ajax in the body.

When there are one or two pairs of these samplers the script works 100% of the time, executing the samplers returning HTTP 200 responses and correctly substituting the id extracted from the first sampler in each pair, then logging out in the final sampler (exit.html). When the third pair of samplers are added I get the SocketException about once every 10-15 executions. With four pairs enabled it happens much more frequently, and with the fifth pair enabled it happens 100% of the time.

The odd thing is the SocketException occurs in the logout sampler, no other sampler. Also, if the logout sampler is disabled the socket exception never occurs, it works 100% of the time.

Here's the full stack trace:

java.net.SocketException: Socket closed
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1676)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1674)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1672)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
at org.apache.jmeter.protocol.http.sampler.HTTPJavaImpl.readResponse(HTTPJavaImpl.java:258)
at org.apache.jmeter.protocol.http.sampler.HTTPJavaImpl.sample(HTTPJavaImpl.java:514)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.followRedirects(HTTPSamplerBase.java:1486)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.resultProcessing(HTTPSamplerBase.java:1561)
at org.apache.jmeter.protocol.http.sampler.HTTPAbstractImpl.resultProcessing(HTTPAbstractImpl.java:338)
at org.apache.jmeter.protocol.http.sampler.HTTPJavaImpl.sample(HTTPJavaImpl.java:588)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1141)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1130)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:431)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:258)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketException: Socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:689)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1324)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:2691)
at java.net.URLConnection.getHeaderFieldLong(URLConnection.java:639)
at java.net.URLConnection.getContentLengthLong(URLConnection.java:511)
at java.net.URLConnection.getContentLength(URLConnection.java:495)
at org.apache.jmeter.protocol.http.sampler.HTTPJavaImpl.readResponse(HTTPJavaImpl.java:224)
... 12 more

I would appreciate any help debugging this

1 Answer 1

1

I believe that you're getting Socket Closed error due to changes to HTTP Requests default settings changes including

  • disabling failing requests
  • disabling stale check

See Connection Reset since JMeter 2.10 ? wiki page for more detailed explanation and options on how to bypass it if you're absolutely sure that the problem is not with your web server.

Also, sending individual HTTP Requests isn't very correct approach for testing AJAX applications as AJAX assumes kicking off extra requests within the bounds of the same parent thread.Current JMeter implementation doesn't allow overriding parent Thread Group limitation so it isn't possible to spawn more than one request at a time using one thread.

Check out How to Load Test AJAX/XHR Enabled Sites With JMeter guide for options on how to properly test AJAX applications.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the response. The problem wasn't the connection reset issue in your link. I used Wireshark to examine the traffic and found that there was a collision between the dashlets where one sample for one sample was closing the connection that another sample from another dashlet needed, thus getting the Socket closed exception. I solved it by recording each dashlet separately into individual transaction controllers, so now there are no collisions.
So now, I have five transaction controllers executing synchronously where in the browser they run asynchronously. In the article you mentioned they say to use the JSR223 Sampler to run the ajax requests, but the example given does not even use ajax as far as I can see. Can you please flesh out how the JSR223 Sampler will solve the issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.