Bug 39808 - Invalid redirect causes incorrect sample time
Invalid redirect causes incorrect sample time
Status: RESOLVED FIXED
Product: JMeter
Classification: Unclassified
Component: HTTP
2.2
PC Windows XP
: P2 minor (vote)
: ---
Assigned To: JMeter issues mailing list
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2006-06-13 22:41 UTC by Bennett
Modified: 2007-04-30 15:52 UTC (History)
0 users



Attachments
Test case: Simple JMeter test plan (6.32 KB, text/plain)
2006-06-14 23:00 UTC, Bennett
Details
Test case: PHP file to generate an invalid redirect (141 bytes, text/plain)
2006-06-14 23:03 UTC, Bennett
Details
Test case: output (3.40 KB, text/plain)
2006-06-14 23:03 UTC, Bennett
Details
Suggested patch (1.71 KB, patch)
2007-04-22 09:27 UTC, Alf Hogemark
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bennett 2006-06-13 22:41:43 UTC
If an HTTP sampler (either type) is set to follow redirects, and the server
returns a redirect to an invalid URL, then the original sample is included twice
as a subsample. Thus the overall sample time is double what it should be.

For example, here is a very simple PHP file that delays 5 seconds and returns a
bad redirect:

<?php
// This file published as http://localhost/bad-redirect.php
sleep(5); // 5 second delay
header("Location: http://HOST:PORT/"); // Invalid redirect
exit;
?>

A trivial JMeter test plan that fetches this file once yeilds the following
result. The test took 5 seconds (timed manually) as expected. But note that the
"error" sub-result appears twice in the results, and the total time shows up as
ten seconds.

It seems to me that HTTPSamplerBase.followRedirects() needs to be fixed.

<?xml version="1.0" encoding="UTF-8"?>
<testResults version="1.1">

<sampleResult timeStamp="1150235700594" dataType="text" threadName="Thread Group
1-1" label="HTTP Request" time="10030" responseMessage="Non HTTP response
message" responseCode="Non HTTP response code" success="false"><sampleResult
timeStamp="1150235700594" dataType="text" threadName="" label="Error"
time="5015" responseMessage="Non HTTP response message" responseCode="Non HTTP
response code" success="false"><property xml:space="preserve"
name="samplerData">GET http://localhost/bad-redirect.php
</property><binary>java.net.MalformedURLException: For input string: "PORT"&#13;
	at java.net.URL.&lt;init&gt;(Unknown Source)&#13;
	at java.net.URL.&lt;init&gt;(Unknown Source)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.followRedirects(HTTPSamplerBase.java:700)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.resultProcessing(HTTPSamplerBase.java:761)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSampler.sample(HTTPSampler.java:493)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:514)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:503)&#13;
	at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:247)&#13;
	at java.lang.Thread.run(Unknown Source)&#13;
</binary></sampleResult><sampleResult timeStamp="1150235700594" dataType="text"
threadName="" label="Error" time="5015" responseMessage="Non HTTP response
message" responseCode="Non HTTP response code" success="false"><property
xml:space="preserve" name="samplerData">GET http://localhost/bad-redirect.php
</property><binary>java.net.MalformedURLException: For input string: "PORT"&#13;
	at java.net.URL.&lt;init&gt;(Unknown Source)&#13;
	at java.net.URL.&lt;init&gt;(Unknown Source)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.followRedirects(HTTPSamplerBase.java:700)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.resultProcessing(HTTPSamplerBase.java:761)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSampler.sample(HTTPSampler.java:493)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:514)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:503)&#13;
	at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:247)&#13;
	at java.lang.Thread.run(Unknown Source)&#13;
</binary></sampleResult><property xml:space="preserve" name="samplerData">GET
http://localhost/bad-redirect.php
</property><binary>java.net.MalformedURLException: For input string: "PORT"&#13;
	at java.net.URL.&lt;init&gt;(Unknown Source)&#13;
	at java.net.URL.&lt;init&gt;(Unknown Source)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.followRedirects(HTTPSamplerBase.java:700)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.resultProcessing(HTTPSamplerBase.java:761)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSampler.sample(HTTPSampler.java:493)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:514)&#13;
	at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:503)&#13;
	at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:247)&#13;
	at java.lang.Thread.run(Unknown Source)&#13;
</binary></sampleResult>
</testResults>
Comment 1 Sebb 2006-06-14 17:08:45 UTC
Can you try with JMeter 2.2 please?
Comment 2 Bennett 2006-06-14 23:00:03 UTC
Created attachment 18469 [details]
Test case: Simple JMeter test plan

This test plan makes a single HTTP request and displays the results.
Comment 3 Bennett 2006-06-14 23:03:03 UTC
Created attachment 18470 [details]
Test case: PHP file to generate an invalid redirect

This PHP file generates an invalid redirect. If a JMeter test plan requests
this, it will trigger this bug.
Comment 4 Bennett 2006-06-14 23:03:57 UTC
Created attachment 18471 [details]
Test case: output

This is the XML output generated by the test case. Note the doubled sample
result.
Comment 5 Bennett 2006-06-14 23:14:54 UTC
The problem still occurs in JMeter 2.2. I have updated the version number in
this bug.

I suspect that the problem is in HTTPSamplerBase.followRedirects(), which has
not changed since last year.
Comment 6 Sebb 2006-06-15 21:33:58 UTC
What happens is that JMeter tries to follow the redirect, but ends up retrying
the initial URL, as it was unable to generate the correct URL to follow.

I'm not quite sure what it should do in the circumstances - it would be better
if it did not retry the original URL, but it cannot try the new URL.

Maybe it should just generate an invalid sample result. But it won't be able to
store the location in the usual place, as it is not a valid URL.

Given that the server has generated an invalid Location header, I don't think
this is a serious problem, so I've downgraded the severity.
Comment 7 Sebb 2006-06-15 21:44:42 UTC
Sorry, that was wrong - it does not try to follow the original URL, but it does
generate an extra sample.

This should still be fixed if possible - but of course the server should really
be fixed so it generates a valid redirect.
Comment 8 Alf Hogemark 2007-04-22 09:27:08 UTC
Created attachment 20013 [details]
Suggested patch

Patch to avoid duplicate samples being added, if the URL we are told to
redirect to is malformed.
Comment 9 Sebb 2007-04-30 15:52:08 UTC
Thanks - applied to SVN in r533872