plainblack.com
Username Password
search
Bookmark and Share
View All Tickets
dbSlave breaks WebGUI when not able to connect  (#12305)
Issue

We had a problem where our db read VIP had an outage. This VIP was used in WebGUI as a dbslave.

One of the sites in the shared install failed:

DBI connect('www_example_com;host=xxx.xxx.xxx.xxx','username',...) failed: Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (113) at /data/WebGUI/lib/WebGUI/SQL.pm line 433

was running fine (same slave IP, other db). My suspicion is that on the failing site, a module actually tried to open the slave, which triggered the error.

In my opinion, the problem of not being able to connect to a slave shouldn't break WebGUI in any circumstances (especially with the scarceness of the slave being actually used). It should notify the administrator

I haven't tracked down what module might be responsible for calling the slave (and thus whether my assumptions are correct), but if I'm correct, I think this should be resolved in Session.pm, which builds the object.

maybe a related bug:
http://www.webgui.org/bugs/tracker/fatal-error-with-regard-to-dbslaves

Solution Summary
Comments
bartjol
0
11/28/2011 6:36 am
this might very well have been the paginator, which is (attempted to be) instantiated on the failing site and not on the other site
bartjol
0
11/28/2011 6:57 am
This should check this:

lib/WebGUI/Session.pm line 235:237
   if (!exists $self->{_slave}) {
       return $self->db;
   }

Which should return $self->db when you combine it with:

WebGUI/SQL.pm: line 437-441
       unless (defined $dbh) {
               $session->errorHandler->error("Couldn't connect to database: $dsn : $DBI::errstr");
               return undef;
       }

So that the error is thrown isn't a problem, but after that something goes awry. So it looks a bit like the expected failing of the !exists statement doesn't happen
bartjol
0
11/28/2011 8:14 am
build in a tmp error to check whether wg thinks the slave does exist or not and found that on a failed connection, WG thinks that the slave exists
bartjol
0
11/28/2011 8:28 am
which leads to 2 possible fixes:
1st: in the 3rd line of code the object only should be created when the connect function doesn't throw an error
2nd: in the 6th line of code the check whether a valid object exists must be improved.

      if (scalar @slaves > 0) {
           my $slave = $slaves[rand @slaves];
           $self->{_slave} = WebGUI::SQL->connect($self, $slave->{dsn},$slave->{user},$slave->{pass});
       }
   }
   if (!exists $self->{_slave}) {
       $self->errorHandler->fatal("dbslave does not exist according to wg");
       return $self->db;
bartjol
0
11/28/2011 8:36 am
I see that the code for this is identical in WG8, so I expect the bug to be too
bartjol
0
11/28/2011 10:37 am
it looks like replacing
if (!exists $self->{_slave}) {
with
   if ($self->{_slave} == undef ) {

does the job
bartjol
0
11/28/2011 10:48 am
tested it (as far as manual testing goes) that it also works with a working dbslave
bartjol
0
11/28/2011 10:52 am
maybe

   if (!exists $self->{_slave} || $self->{_slave} == undef ) {

would be better as it covers the non-existence and the existence if it is not properly constructed. SQL.pm returns undef when it fails. With the mentioned statement both failings are covered
bartjol
0
11/29/2011 2:59 am
added in my github:
https://github.com/BartJol/webgui/commit/c739b56c9db922157c0a9985850eccead8730245

Unfortunately I couldn't do a pull request, as it took along some other commits that shouldn't be included
perlDreamer
0
5/28/2012 4:28 pm
Added code similar to the git commit to fix the issue.

Fixed in 7.10.24(fd4b75b)
bartjol
0
6/1/2012 9:33 am
thanks
Details
Ticket Status Closed  
Rating0.0 
Submitted Bybartjol 
Date Submitted2011-11-28 
Assigned To unassigned  
Date Assigned2019-05-22 
Assigned By 
Severity Critical (mostly not working)  
What's the bug in? WebGUI Stable  
WebGUI / WRE Version 7.10.23  
URLuse/bugs/tracker/12305
Keywords
Ticket History
6/1/2012
2:33 PM
Closed bartjol
5/28/2012
9:29 PM
Resolved perlDreamer
11/28/2011
12:23 PM
Ticket created bartjol
© 2019 Plain Black Corporation | All Rights Reserved