On 02/22/2017 03:20 PM, Benjamins, John wrote:
> Hi,
> 
> Sorry, you are right, it is actually using Dancer2::Plugin::Pg.  
> Unfortunately I did not write this code, so I am not sure why it is checking 
> $?, but that would seem to be a way to get unexpected results (which is what 
> we are seeing!).  What is the correct way to check the result of something 
> like:  $pg->selectAll( $query, $env_name )?  How do I know the error 
> returned, if any?  Sorry if this is a basic question...
> 
> Thank you again!
> 
> John 

Hello John,

this plugin uses DBI behind the scenes - so if you have set RaiseError: 1, it 
will cause a 500 if the query fails.

So checking $? is itself causing unexpected results. If you want to see if a 
query crashes, you can wrap the
selectall call in an eval and check $@ - that makes more sense.

Regards
        Racke

> 
> -----Original Message-----
> From: dancer-users [mailto:[email protected]] On Behalf Of 
> Stefan Hornburg (Racke)
> Sent: Wednesday, February 22, 2017 7:40 AM
> To: [email protected]
> Subject: Re: [dancer-users] Problem with web service using dancer2
> 
> On 02/22/2017 01:32 PM, Benjamins, John wrote:
>> Hi,
>>
>> The log has this for one of 20 threads with PID 37775:
>>
>> [37775] Read 366 bytes: "GET /v1/environments/testtest1/requests 
>> HTTP/1.1\r\nHost: apews:8096\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.1; 
>> WOW64; rv:51.0) Gecko/20100101 Firefox/51.0\r\nAccept: application/json, 
>> text/javascript, */*; q=0.01\r\nAccept-Language: 
>> en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nReferer: 
>> http://apews:8080/ape_mgmt/\r\nOrigin: http://apews:8080\r\nConnection: 
>> keep-alive\r\n\r\n"
>> [EnvMgmt:37775] core @2017-02-22 02:17:09> looking for get 
>> /v1/environments/testtest1/requests in 
>> /usr/local/share/perl5/Dancer2/Core/App.pm l. 34 [EnvMgmt:37775] core 
>> @2017-02-22 02:17:09> Entering hook core.app.before_request in (eval 
>> 176) l. 1 [EnvMgmt:37775] info @2017-02-22 02:17:09> Sub: 
>> get_env_requests_status -- Query: select request_id AS requestnumber, 
>> client_code AS clientcode, request_status AS requeststatus, entity_id AS 
>> environment, request_url AS requesturl, request_method AS requestmethod, 
>> request_desc AS requestdesc, created_timestamp AS createdtime from 
>> entity_requests where entity_id = 'testtest1' in 
>> /home/dancer2/EnvMgmt/bin/../lib/EnvUtils.pm l. 240 [EnvMgmt:37775] info 
>> @2017-02-22 02:17:09> Sub: get_env_requests_status -- Exitcode: 
>> 72057594037927935 in /home/dancer2/EnvMgmt/bin/../lib/EnvUtils.pm l. 255 
>> [EnvMgmt:37775] info @2017-02-22 02:17:09> ERROR: ARRAY(0x3e73f90) $VAR1 = [
>>           { .... (data removed for brevity) ... }
>>         ]; in /home/dancer2/EnvMgmt/bin/../lib/EnvUtils.pm l. 259 
>> [EnvMgmt:37775] core @2017-02-22 02:17:09> Entering hook 
>> core.app.after_request in (eval 176) l. 1 [37775] Wrote 285 bytes 
>> [37775] Wrote 5 bytes [37775] Request done [37775] Waiting on previous 
>> connection for keep-alive request...
>> [37775] Closing connection
>>
>> The code around l. 255  in EnvUtils.pm is:
>>
>> #
>> # Get requests status for selected environment.
>> #
>>
>> sub get_env_requests_status {
>>   my ($env_name) = @_;
>>
>>  # $env_name = $env_name . '%';
>>
>>   my $pg = Pg;
>>   my $debug = 'select request_id AS requestnumber,' .
>>               ' client_code AS clientcode,' .
>>               ' request_status AS requeststatus,' .
>>               ' entity_id AS environment,' .
>>               ' request_url AS requesturl,' .
>>               ' request_method AS requestmethod,' .
>>               ' request_desc AS requestdesc,' .
>>               ' created_timestamp AS createdtime' .
>>               ' from entity_requests' .
>>               ' where entity_id = \'' . $env_name . '\'';
>>   info "Sub: get_env_requests_status -- Query: $debug";
>>
>>   my $query = 'select request_id AS requestnumber,' .
>>               '       client_code AS clientcode,' .
>>               '       request_status AS requeststatus,' .
>>               '       entity_id AS environment,' .
>>               '       request_url AS requesturl,' .
>>               '       request_method AS requestmethod,' .
>>               '       request_desc AS requestdesc,' .
>>               '       created_timestamp AS createdtime' .
>>               '  from entity_requests' .
>>               ' where entity_id = ?';
>>   my $result = $pg->selectAll( $query, $env_name );
>>   my $exitcode = $? >> 8;
>>
>>   info "Sub: get_env_requests_status -- Exitcode: $exitcode";
>>
>>   if ($exitcode) {
>>     my $str = sprintf("%s", Dumper($result));
>>     info "ERROR: $result $str";
>>     return 372;  # Error: Cannot select the request status for selected env.
>>   }
>>
>>   return @{$result};
>> };
>>
>> And we are using Data::Dumper to print the $result of the query.
>>
>> Thank you!
>>
>> John
> 
> Hello John,
> 
> I thought you are using DBI ... but what kind of module is Pg?
> 
> At any rate, it looks odd to me to query the exit code when you don't run an 
> external command.
> 
> Also I would use q{} or qq{} instead of appending lines with the dot operator.
> 
> Regards
>           Racke
> 
>>
>> -----Original Message-----
>> From: dancer-users [mailto:[email protected]] On Behalf 
>> Of Stefan Hornburg (Racke)
>> Sent: Wednesday, February 22, 2017 7:03 AM
>> To: [email protected]
>> Subject: Re: [dancer-users] Problem with web service using dancer2
>>
>> On 02/22/2017 12:56 PM, Benjamins, John wrote:
>>> Hi,
>>>
>>>  
>>>
>>> We are using Dancer2 (version is 0.203001) to provide a web service, and 
>>> this has been deployed in a Docker container. 
>>> It is using Postgres as a database backend and perl DBI.  We are 
>>> having an issue were the service starts to return error
>>> 500 from database queries, even though it is returning what appears 
>>> to be valid data.  Any suggestions on where we should start looking?
>>> Restarting the pod running the web service fixes the issue for a while, but 
>>> after a day or so of activity, the issue comes back.
>>>
>>>  
>>>
>>> Please let me know if there is any additional information I can provide 
>>> that would help describe the problem better.
>>>
>>>  
>>>
>>> Thanks,
>>>
>>
>> Hello,
>>
>> what does Dancer report in the log file about the reason of the 500 error?
>>
>> Regards
>>           Racke
>>
>>>  
>>>
>>>  
>>>
>>>  
>>>
>>> This message is marked *Public*
>>>
>>> ---------------------------------------------------------------------
>>> -
>>> --------------------------------------------------
>>> Please consider the environment before printing this email and any 
>>> attachments.
>>>
>>> This e-mail and any attachments are intended only for the individual 
>>> or company to which it is addressed and may contain information which is 
>>> privileged, confidential and prohibited from disclosure or unauthorized use 
>>> under applicable law.
>>> If you are not the intended recipient of this e-mail, you are hereby 
>>> notified that any use, dissemination, or copying of this e-mail or 
>>> the information contained in this e-mail is strictly prohibited by the 
>>> sender. If you have received this transmission in error, please return the 
>>> material received to the sender and delete all copies from your system.
>>>
>>>
>>>
>>> _______________________________________________
>>> dancer-users mailing list
>>> [email protected]
>>> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>>>
>>
>>
>> --
>> Ecommerce and Linux consulting + Perl and web application programming.
>> Debian and Sympa administration.
>> _______________________________________________
>> dancer-users mailing list
>> [email protected]
>> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>>
>> This message is marked Public
>>
>>
>> Please consider the environment before printing this email and any 
>> attachments.
>>
>> This e-mail and any attachments are intended only for the individual or 
>> company to which it is addressed and may contain information which is 
>> privileged, confidential and prohibited from disclosure or unauthorized use 
>> under applicable law. If you are not the intended recipient of this e-mail, 
>> you are hereby notified that any use, dissemination, or copying of this 
>> e-mail or the information contained in this e-mail is strictly prohibited by 
>> the sender. If you have received this transmission in error, please return 
>> the material received to the sender and delete all copies from your system.
>> _______________________________________________
>> dancer-users mailing list
>> [email protected]
>> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>>
> 
> 
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration.
> _______________________________________________
> dancer-users mailing list
> [email protected]
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
> 
> This message is marked Public
> 
> 
> Please consider the environment before printing this email and any 
> attachments.
> 
> This e-mail and any attachments are intended only for the individual or 
> company to which it is addressed and may contain information which is 
> privileged, confidential and prohibited from disclosure or unauthorized use 
> under applicable law. If you are not the intended recipient of this e-mail, 
> you are hereby notified that any use, dissemination, or copying of this 
> e-mail or the information contained in this e-mail is strictly prohibited by 
> the sender. If you have received this transmission in error, please return 
> the material received to the sender and delete all copies from your system.
> _______________________________________________
> dancer-users mailing list
> [email protected]
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
> 


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.
_______________________________________________
dancer-users mailing list
[email protected]
http://lists.preshweb.co.uk/mailman/listinfo/dancer-users

Reply via email to