D
David Karr
I have a Perl script that uses LWP::UserAgent to run a series of tests against a REST service running in an intranet. I configure it with a host and port to run its tests against. I've been using it for a while with no significant problems. Yesterday I started running tests against another serverwhere my service was just deployed. This is a "final stage" environment, prior to production. My service is already deployed to production, this isjust an additional release.
For some reason, while running its tests against this new server, after getting numerous successful results back, the script is failing at no particular request with "500 read failed: Software caused connection abort". Even more curious, when I check the "access.log" on the server for that particular request, it reports a 200.
When I try to run that specific request manually, it always works fine. I also just checked with a QA tester that's using SoapUI to do similar testing, and he hasn't seen any problems.
So, it seems like there's something in my Perl script that is causing some sort of a race condition that makes it think a request fails, when the server sees no problem.
I'll show the head of my Perl script, along with the excerpt of the code that makes the request and checks for success.
-------------------
#!/usr/bin/perl -w
# -*- mode: Perl; -*-
use threads;
use threads::shared;
use Thread:ool;
use Getopt::Long;
use LWP::UserAgent;
use HTTP::Request::Common qw(GET);
use XML::XPath;
use XML::XPath::XMLParser;
use Time::HiRes qw/gettimeofday/;
use List::MoreUtils qw(uniq);
....
sub sendGet($) {
my ($url) = @_;
if ($url =~ /\?/) {
foreach my $param (@opt_params) {
$url = $url . "&" . $param;
}
}
else {
$url = $url . "?";
foreach my $param (@opt_params) {
$url = $url . $param . "&";
}
}
print localtime() . ": url[$url]\n";
my $request = GET $url;
$request->header("X-Client-Code", "abc");
eval {
my $response = $ua->request($request);
if ($response->is_success) {
return $response->decoded_content;
}
else {
print "Call to url \"" . $url . "\" failed: " .
$response->status_line . "\n";
}
1;
} or do {
print "Call to url \"" . $url . "\" failed.\n";
}
}
For some reason, while running its tests against this new server, after getting numerous successful results back, the script is failing at no particular request with "500 read failed: Software caused connection abort". Even more curious, when I check the "access.log" on the server for that particular request, it reports a 200.
When I try to run that specific request manually, it always works fine. I also just checked with a QA tester that's using SoapUI to do similar testing, and he hasn't seen any problems.
So, it seems like there's something in my Perl script that is causing some sort of a race condition that makes it think a request fails, when the server sees no problem.
I'll show the head of my Perl script, along with the excerpt of the code that makes the request and checks for success.
-------------------
#!/usr/bin/perl -w
# -*- mode: Perl; -*-
use threads;
use threads::shared;
use Thread:ool;
use Getopt::Long;
use LWP::UserAgent;
use HTTP::Request::Common qw(GET);
use XML::XPath;
use XML::XPath::XMLParser;
use Time::HiRes qw/gettimeofday/;
use List::MoreUtils qw(uniq);
....
sub sendGet($) {
my ($url) = @_;
if ($url =~ /\?/) {
foreach my $param (@opt_params) {
$url = $url . "&" . $param;
}
}
else {
$url = $url . "?";
foreach my $param (@opt_params) {
$url = $url . $param . "&";
}
}
print localtime() . ": url[$url]\n";
my $request = GET $url;
$request->header("X-Client-Code", "abc");
eval {
my $response = $ua->request($request);
if ($response->is_success) {
return $response->decoded_content;
}
else {
print "Call to url \"" . $url . "\" failed: " .
$response->status_line . "\n";
}
1;
} or do {
print "Call to url \"" . $url . "\" failed.\n";
}
}