Skip Menu |

This queue is for tickets about the Mojo-Cloudstack CPAN distribution.

Report information
The Basics
Id: 121937
Status: new
Priority: 0/
Queue: Mojo-Cloudstack

People
Owner: Nobody in particular
Requestors: franz.skale [...] citycom-austria.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Bug when using in a mojolicious APP (close_wait due to not resetting the IOLoop)
Date: Tue, 30 May 2017 12:51:09 +0000
To: "bug-Mojo-Cloudstack [...] rt.cpan.org" <bug-Mojo-Cloudstack [...] rt.cpan.org>
From: Skale Franz <franz.skale [...] citycom-austria.com>
Perl Version: 5.24.1 Mojo Cloudstack Version: 0.0.7 Mojolicious: mojo version CORE Perl (v5.24.1, linux) Mojolicious (7.31, Doughnut) OPTIONAL EV 4.0+ (4.22) IO::Socket::SSL 1.94+ (2.048) Net::DNS::Native 0.15+ (0.15) When using Mojo::Cloudstack in a Mojolicious APP, the IO Loop never stops, so on overy new connection, the io loop will be open until stopping the mojolicious app. This small patch fixes the problem by resetting the ioloop on AUTOLOAD: diff -upr Mojo-Cloudstack-0.07/lib/Mojo/Cloudstack.pm Mojo-Cloudstack-0.07.new/lib/Mojo/Cloudstack.pm --- Mojo-Cloudstack-0.07/lib/Mojo/Cloudstack.pm 2015-09-29 17:10:24.000000000 +0200 +++ Mojo-Cloudstack-0.07.new/lib/Mojo/Cloudstack.pm 2017-05-30 09:24:35.937728851 +0200 @@ -5,7 +5,7 @@ use Mojo::Parameters; use Mojo::URL; use Mojo::UserAgent; use Mojo::JSON 'j'; -use Mojo::Util 'slurp'; +use Mojo::File; use Mojo::Collection 'c'; use Mojo::Cloudstack::Base; use Mojo::Cloudstack::Api; @@ -64,8 +64,10 @@ sub AUTOLOAD { my %params = @_; $params{command} = $command; my $req = $self->_build_request(\%params); + my $loop = $self->ioloop; my $res = $self->post($req)->res; my $items = $res->json; + $loop->reset; #warn Dumper 'ITEMS', $items; die sprintf("Could not get response for %s\n%s", $req, Dumper($res)) unless $items; my $responsetype = (keys %$items)[0]; @@ -114,7 +116,7 @@ sub _load_api_cache { if ($force or (not -f $cf)); #TODO File::ShareDir - $self->api_cache(j(slurp $cf)) if -f $cf; + $self->api_cache(j(Mojo::File->new($cf)->slurp)) if -f $cf; return $self->api_cache; } Also please fix the issue regarding the deprecated slurp function which is now part of Mojo::File. Here a temp fix to get Mojo::Cloudstack working with Mojolicious 7.31 diff -upr Mojo-Cloudstack-0.07/ex/createvm.pl Mojo-Cloudstack-0.07.new/ex/createvm.pl --- Mojo-Cloudstack-0.07/ex/createvm.pl 2015-09-29 17:10:24.000000000 +0200 +++ Mojo-Cloudstack-0.07.new/ex/createvm.pl 2017-05-30 09:27:22.071150461 +0200 @@ -1,12 +1,12 @@ #!/usr/bin/perl -use Mojo::Util 'slurp'; +use Mojo::File; use Data::Dumper 'Dumper'; use Mojo::Cloudstack; -my $api_key = slurp("/home/holger/.mojo_cloudstack/api_key"); +my $api_key = Mojo::File->new('/home/holger/.mojo_cloudstack/api_key')->slurp; chomp $api_key; -my $secret_key = slurp("/home/holger/.mojo_cloudstack/secret_key"); +my $secret_key = Mojo::File->new('/home/holger/.mojo_cloudstack/secret_key')->slurp; chomp $secret_key; my $cs = Mojo::Cloudstack->new( diff -upr Mojo-Cloudstack-0.07/ex/delete_all_volumes_by_customer.pl Mojo-Cloudstack-0.07.new/ex/delete_all_volumes_by_customer.pl --- Mojo-Cloudstack-0.07/ex/delete_all_volumes_by_customer.pl 2015-09-29 17:10:24.000000000 +0200 +++ Mojo-Cloudstack-0.07.new/ex/delete_all_volumes_by_customer.pl 2017-05-30 09:28:35.408260817 +0200 @@ -1,12 +1,12 @@ #!/usr/bin/perl -use Mojo::Util 'slurp'; +use Mojo::File; use Data::Dumper 'Dumper'; use Mojo::Cloudstack; -my $api_key = slurp("/home/holger/.mojo_cloudstack/api_key"); +my $api_key = Mojo::File->new('/home/holger/.mojo_cloudstack/api_key')->slurp; chomp $api_key; -my $secret_key = slurp("/home/holger/.mojo_cloudstack/secret_key"); +my $secret_key = Mojo::File->new('/home/holger/.mojo_cloudstack/secret_key')->slurp; chomp $secret_key; my $cs = Mojo::Cloudstack->new( diff -upr Mojo-Cloudstack-0.07/ex/expunge_destroyed_vms.pl Mojo-Cloudstack-0.07.new/ex/expunge_destroyed_vms.pl --- Mojo-Cloudstack-0.07/ex/expunge_destroyed_vms.pl 2015-09-29 17:10:24.000000000 +0200 +++ Mojo-Cloudstack-0.07.new/ex/expunge_destroyed_vms.pl 2017-05-30 09:29:17.256611867 +0200 @@ -1,12 +1,12 @@ #!/usr/bin/perl -use Mojo::Util 'slurp'; +use Mojo::File; use Data::Dumper 'Dumper'; use Mojo::Cloudstack; -my $api_key = slurp("/home/holger/.mojo_cloudstack/api_key"); +my $api_key = Mojo::File->new('/home/holger/.mojo_cloudstack/api_key')->slurp; chomp $api_key; -my $secret_key = slurp("/home/holger/.mojo_cloudstack/secret_key"); +my $secret_key = Mojo::File->new('/home/holger/.mojo_cloudstack/secret_key')->slurp; chomp $secret_key; my $cs = Mojo::Cloudstack->new( diff -upr Mojo-Cloudstack-0.07/ex/listapi.pl Mojo-Cloudstack-0.07.new/ex/listapi.pl --- Mojo-Cloudstack-0.07/ex/listapi.pl 2015-09-29 17:10:24.000000000 +0200 +++ Mojo-Cloudstack-0.07.new/ex/listapi.pl 2017-05-30 09:30:02.644825007 +0200 @@ -1,12 +1,12 @@ #!/usr/bin/perl -use Mojo::Util 'slurp'; +use Mojo::File; use Data::Dumper 'Dumper'; use Mojo::Cloudstack; -my $api_key = slurp("/home/holger/.mojo_cloudstack/api_key"); +my $api_key = Mojo::File->new('/home/holger/.mojo_cloudstack/api_key')->slurp; chomp $api_key; -my $secret_key = slurp("/home/holger/.mojo_cloudstack/secret_key"); +my $secret_key = Mojo::File->new('/home/holger/.mojo_cloudstack/secret_key')->slurp; chomp $secret_key; my $cs = Mojo::Cloudstack->new( diff -upr Mojo-Cloudstack-0.07/ex/login.pl Mojo-Cloudstack-0.07.new/ex/login.pl --- Mojo-Cloudstack-0.07/ex/login.pl 2015-09-29 17:10:24.000000000 +0200 +++ Mojo-Cloudstack-0.07.new/ex/login.pl 2017-05-30 09:31:08.542230044 +0200 @@ -1,12 +1,12 @@ #!/usr/bin/perl -use Mojo::Util 'slurp'; +use Mojo::File; use Data::Dumper 'Dumper'; use Mojo::Cloudstack; -my $api_key = slurp("/home/holger/.mojo_cloudstack/api_key"); +my $api_key = Mojo::File->new('/home/holger/.mojo_cloudstack/api_key')->slurp; chomp $api_key; -my $secret_key = slurp("/home/holger/.mojo_cloudstack/secret_key"); +my $secret_key = Mojo::File->new('/home/holger/.mojo_cloudstack/secret_key')->slurp; chomp $secret_key; my $cs = Mojo::Cloudstack->new( diff -upr Mojo-Cloudstack-0.07/lib/Mojo/Cloudstack.pm Mojo-Cloudstack-0.07.new/lib/Mojo/Cloudstack.pm --- Mojo-Cloudstack-0.07/lib/Mojo/Cloudstack.pm 2015-09-29 17:10:24.000000000 +0200 +++ Mojo-Cloudstack-0.07.new/lib/Mojo/Cloudstack.pm 2017-05-30 09:24:35.937728851 +0200 @@ -5,7 +5,7 @@ use Mojo::Parameters; use Mojo::URL; use Mojo::UserAgent; use Mojo::JSON 'j'; -use Mojo::Util 'slurp'; +use Mojo::File; use Mojo::Collection 'c'; use Mojo::Cloudstack::Base; use Mojo::Cloudstack::Api; @@ -64,8 +64,10 @@ sub AUTOLOAD { my %params = @_; $params{command} = $command; my $req = $self->_build_request(\%params); + my $loop = $self->ioloop; my $res = $self->post($req)->res; my $items = $res->json; + $loop->reset; #warn Dumper 'ITEMS', $items; die sprintf("Could not get response for %s\n%s", $req, Dumper($res)) unless $items; my $responsetype = (keys %$items)[0]; @@ -114,7 +116,7 @@ sub _load_api_cache { if ($force or (not -f $cf)); #TODO File::ShareDir - $self->api_cache(j(slurp $cf)) if -f $cf; + $self->api_cache(j(Mojo::File->new($cf)->slurp)) if -f $cf; return $self->api_cache; } diff -upr Mojo-Cloudstack-0.07/t/00-load.t Mojo-Cloudstack-0.07.new/t/00-load.t --- Mojo-Cloudstack-0.07/t/00-load.t 2015-09-29 17:10:24.000000000 +0200 +++ Mojo-Cloudstack-0.07.new/t/00-load.t 2017-05-30 09:22:53.721780782 +0200 @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More 'no_plan'; use Mojo::UserAgent; -use Mojo::Util 'slurp'; +use Mojo::File; use Mojo::JSON 'j'; use Data::Dumper 'Dumper'; @@ -15,9 +15,9 @@ BEGIN { diag("Testing Mojo::Cloudstack $Mojo::Cloudstack::VERSION, Perl $], $^X"); -my $api_key = slurp("t/api_key"); +my $api_key = Mojo::File->new('t/api_key')->slurp; chomp $api_key; -my $secret_key = slurp("t/secret_key"); +my $secret_key = Mojo::File->new('t/secret_key')->slurp; chomp $secret_key; my $cs = Mojo::Cloudstack->new( Best regards. Franz