pplu / aws-sdk-perl

A community AWS SDK for Perl Programmers
Other
168 stars 94 forks source link

Ungraceful handling of "out-of-format" HTTP 500 errors #298

Open leonerd opened 5 years ago

leonerd commented 5 years ago

In writing a small unit test, I've got a little server that serves a blank "500" status error with no body content, to an EC2 request. This upsets the EC2 response parser, because it seems to demand there be a body containing XML data.

This would cause unhelpful and hard-to-debug problems via e.g. HTTP proxies that served plaintext (or otherwise nonvalid XML) responses on things like server failures.

leonerd commented 5 years ago

E.g. by responding with simply

$stream->write(
  "HTTP/1.1 500 Go Away\x0D\x0A" .
  "Content-Length: 0\x0D\x0A" .
  "\x0D\x0A",
  sub {
    $stream->close_gracefully;
  }
);

I get an error:

HTTP error with no body in HTTP response

Trace begun at /home/leo/SC/ziprecruiter/aws-sdk-perl/lib/Paws/Net/XMLResponse.pm line 55
Paws::Net::XMLResponse::error_to_exception('Paws::Net::XMLResponse=HASH(0x55ee8cd2f780)', 'Paws::EC2::DescribeInstances=HASH(0x55ee8d315ba8)', 'Paws::Net::APIResponse=HASH(0x55ee8d4045e8)') called at /home/leo/SC/ziprecruiter/aws-sdk-perl/lib/Paws/Net/XMLResponse.pm line 46
Paws::Net::XMLResponse::process('Paws::Net::XMLResponse=HASH(0x55ee8cd2f780)', 'Paws::EC2::DescribeInstances=HASH(0x55ee8d315ba8)', 'Paws::Net::APIResponse=HASH(0x55ee8d4045e8)') called at /home/leo/SC/ziprecruiter/aws-sdk-perl/lib/Paws/Net/MojoAsyncCaller.pm line 69
Paws::Net::MojoAsyncCaller::__ANON__('Mojo::UserAgent=HASH(0x55ee8ae7af18)', 'Mojo::Transaction::HTTP=HASH(0x55ee8d3c01b8)') called at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Mojo/UserAgent.pm line 252
Mojo::UserAgent::_finish('Mojo::UserAgent=HASH(0x55ee8ae7af18)', 'b39c9ca639515ffc53f6827cd6d1f893') called at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Mojo/UserAgent.pm line 262
Mojo::UserAgent::_read('Mojo::UserAgent=HASH(0x55ee8ae7af18)', 'b39c9ca639515ffc53f6827cd6d1f893', 'HTTP/1.1 500 Go Away^M^JContent-Length: 0^M^J^M^J') called at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Mojo/UserAgent.pm line 134
Mojo::UserAgent::__ANON__('Mojo::IOLoop::Stream=HASH(0x55ee89592738)') called at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Mojo/EventEmitter.pm line 15
Mojo::EventEmitter::emit('Mojo::IOLoop::Stream=HASH(0x55ee89592738)', 'read', 'HTTP/1.1 500 Go Away^M^JContent-Length: 0^M^J^M^J') called at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Mojo/IOLoop/Stream.pm line 103
Mojo::IOLoop::Stream::_read('Mojo::IOLoop::Stream=HASH(0x55ee89592738)') called at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Mojo/IOLoop/Stream.pm line 51
Mojo::IOLoop::Stream::__ANON__('Mojo::Reactor::EV=HASH(0x55ee8c6e0dc0)') called at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Mojo/Reactor/Poll.pm line 143
eval {...} at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Mojo/Reactor/Poll.pm line 143
Mojo::Reactor::Poll::_try('Mojo::Reactor::EV=HASH(0x55ee8c6e0dc0)', 'I/O watcher', 'CODE(0x55ee8d344a00)', 0) called at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Mojo/Reactor/EV.pm line 46
Mojo::Reactor::EV::__ANON__('EV::IO=SCALAR(0x55ee8d3bdc18)', 1) called at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Mojo/Reactor/EV.pm line 21
eval {...} at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Mojo/Reactor/EV.pm line 21
Mojo::Reactor::EV::one_tick('Mojo::Reactor::EV=HASH(0x55ee8c6e0dc0)') called at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Mojo/IOLoop.pm line 85Mojo::IOLoop::one_tick('Mojo::IOLoop=HASH(0x55ee8c6cc6c8)') called at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Future/Mojo.pm line 61
Future::Mojo::await('Future::Mojo=HASH(0x55ee8d344da8)') called at /home/leo/SC/ziprecruiter/aws-sdk-perl/local/lib/perl5/Future.pm line 817
Future::get('Future::Mojo=HASH(0x55ee8d344da8)') called at t/28_retries_mojoasynccaller.t line 38
pplu commented 5 years ago

Hi, In t/25_error_on_malformed_response.t we test known malformed responses on all response parsers. Please modify / add as you feel needed.