[Dbix-class] Re: DBIx::Class 0.08192 Exception recursion when connect to database fails

Doug Henderson dougforpres at gmail.com
Fri Jun 29 02:31:05 GMT 2012


FYI - I figured out the cause of the problem.

I'd mistakenly called "load_components" on the Schema object with a couple
of components that were (among other things) "ISA Row".  Since Row also has
a "throw_exception" method, perl was choosing that one to call instead of
the one in Schema... thus causing all of my pain.

Hopefully this will serve as a warning to others.

Doug

On Mon, Jun 25, 2012 at 9:23 PM, Doug Henderson <dougforpres at gmail.com>wrot=
e:

> Hello,
>
> I apologize if this has been asked before, but I've scanned the mailing
> list archives back to 01/2011 and I didn't see anything obvious.
>
> I'm using DBIx::Class 0.08192 with perl 5.8.8 to talk to MySQL 5.5 and
> everything works perfectly until the database server is offline.
>
> If the database server is accepting connections - everything works great!
> If the database server is stopped (or unreachable) - things get rather
> more exciting.
> Essentially, the connect method throws an error, which is caught.  The
> catching code tries to figure out what to do with it, and during the
> process it itself generates an exception, which seems to be re-caught by
> the original catch method, and around we go.  Eventually the process
> literally runs out of memory... but during the process the machine is
> bought to its knees.
>
> Here is (part) of the stacktrace when the problem occurs... names and
> addresses have been changed to protect the guilty.
> This is the first query the app is trying to perform after starting, and
> as a result it is trying to connect to the database in the process.
>
> Those "top two" exceptions just keep at it until the machine breaks.  As I
> say, works perfectly when connection succeeds.
>
> $ =3D DBIx::Class::Row::result_source(ref(My::Test::Schema)) called from
> file `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Row.pm' line 1441
> $ =3D DBIx::Class::Row::throw_exception(ref(My::Test::Schema), 'No result
> source instance registered for My::Test::Schema, did you forget to call
> My::Test::Schema->table(...)
> ?') called from file `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Row.pm'
> line 1284
> $ =3D DBIx::Class::Row::result_source(ref(My::Test::Schema)) called from
> file `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Row.pm' line 1441
> $ =3D DBIx::Class::Row::throw_exception(ref(My::Test::Schema), 'No result
> source instance registered for My::Test::Schema, did you forget to call
> My::Test::Schema->table(...)
> ?') called from file `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Row.pm'
> line 1284
> $ =3D DBIx::Class::Row::result_source(ref(My::Test::Schema)) called from
> file `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Row.pm' line 1441
> $ =3D DBIx::Class::Row::throw_exception(ref(My::Test::Schema), 'No result
> source instance registered for My::Test::Schema, did you forget to call
> My::Test::Schema->table(...)
> ?') called from file `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Row.pm'
> line 1284
> $ =3D DBIx::Class::Row::result_source(ref(My::Test::Schema)) called from
> file `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Row.pm' line 1441
> $ =3D DBIx::Class::Row::throw_exception(ref(My::Test::Schema), 'No result
> source instance registered for My::Test::Schema, did you forget to call
> My::Test::Schema->table(...)
> ?') called from file `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Row.pm'
> line 1284
> $ =3D DBIx::Class::Row::result_source(ref(My::Test::Schema)) called from
> file `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Row.pm' line 1441
> $ =3D DBIx::Class::Row::throw_exception(ref(My::Test::Schema), 'No result
> source instance registered for My::Test::Schema, did you forget to call
> My::Test::Schema->table(...)
> ?') called from file `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Row.pm'
> line 1284
> $ =3D DBIx::Class::Row::result_source(ref(My::Test::Schema)) called from
> file `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Row.pm' line 1441
> . =3D DBIx::Class::Row::throw_exception(ref(My::Test::Schema), 'DBI
> Connection failed: DBI connect(\'db:db.test.com\',\'user\',...) failed:
> Can\'t connect to MySQL server on \'db.test.com\' (111) at
> /usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI.pm line 1248^J')
> called from file `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage.pm'
> line 112
> . =3D
> DBIx::Class::Storage::throw_exception(ref(DBIx::Class::Storage::DBI::mysq=
l),
> 'DBI Connection failed: DBI connect(\'db:db.test.com\',\'user\',...)
> failed: Can\'t connect to MySQL server on \'db.test.com\' (111) at
> /usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI.pm line 1248^J')
> called from file
> `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI.pm' line 1301
> . =3D
> DBIx::Class::Storage::DBI::__ANON__[/usr/lib/perl5/vendor_perl/5.8.8/DBIx=
/Class/Storage/DBI.pm:1302]('DBI
> connect(\'db:db.test.com\',\'user\',...) failed: Can\'t connect to MySQL
> server on \'db.test.com\' (111) at
> /usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI.pm line 1248^J')
> called from file `/usr/lib/perl5/vendor_perl/5.8.8/Try/Tiny.pm' line 100
> . =3D Try::Tiny::try(ref(CODE), ref(Try::Tiny::Catch),
> ref(Try::Tiny::Finally)) called from file
> `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI.pm' line 1305
> @ =3D
> DBIx::Class::Storage::DBI::_connect(ref(DBIx::Class::Storage::DBI::mysql),
> 'dbi:mysql:db:db.test.com', 'user', 'secret', ref(HASH)) called from file
> `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI.pm' line 1007
> . =3D
> DBIx::Class::Storage::DBI::_populate_dbh(ref(DBIx::Class::Storage::DBI::m=
ysql))
> called from file
> `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI.pm' line 936
> $ =3D
> DBIx::Class::Storage::DBI::_get_dbh(ref(DBIx::Class::Storage::DBI::mysql))
> called from file
> `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI.pm' line 1115
> $ =3D
> DBIx::Class::Storage::DBI::__ANON__[/usr/lib/perl5/vendor_perl/5.8.8/DBIx=
/Class/Storage/DBI.pm:1115]()
> called from file `/usr/lib/perl5/vendor_perl/5.8.8/Try/Tiny.pm' line 74
> $ =3D eval {...} called from file
> `/usr/lib/perl5/vendor_perl/5.8.8/Try/Tiny.pm' line 67
> $ =3D Try::Tiny::try(ref(CODE)) called from file
> `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI.pm' line 1115
> $ =3D
> DBIx::Class::Storage::DBI::_dbh_get_info(ref(DBIx::Class::Storage::DBI::m=
ysql),
> 18) called from file
> `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI/mysql.pm' line 63
> $ =3D
> DBIx::Class::Storage::DBI::mysql::sql_maker(ref(DBIx::Class::Storage::DBI=
::mysql))
> called from file
> `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI.pm' line 2101
> @ =3D
> DBIx::Class::Storage::DBI::_select_args(ref(DBIx::Class::Storage::DBI::my=
sql),
> ref(ARRAY), ref(ARRAY), ref(HASH), ref(HASH)) called from file
> `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI.pm' line 2077
> @ =3D
> DBIx::Class::Storage::DBI::_select(ref(DBIx::Class::Storage::DBI::mysql),
> ref(ARRAY), ref(ARRAY), ref(HASH), ref(HASH)) called from file
> `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/Storage/DBI.pm' line 2211
> @ =3D
> DBIx::Class::Storage::DBI::select_single(ref(DBIx::Class::Storage::DBI::m=
ysql),
> ref(ARRAY), ref(ARRAY), ref(HASH), ref(HASH)) called from file
> `/usr/lib/perl5/vendor_perl/5.8.8/DBIx/Class/ResultSet.pm' line 975
> $ =3D DBIx::Class::ResultSet::single(ref(DBIx::Class::ResultSet)) called
> from file `/usr/lib/perl5/vendor_perl/5.8.8/My/Test/Manager.pm' line 115
> $ =3D My::Test::Manager::get_node(ref(My::Test::Manager), 127.0.0.1) call=
ed
> from file `~/test.pl' line 171
>
>
> Here is some debugging (including a couple of key vars) from when this was
> occurring:
>
> 1279        ? $_[0]->{_result_source} =3D $_[1]
> 1280
> 1281        # note this is a || not a ||=3D, the difference is important
> 1282=3D=3D>     : $_[0]->{_result_source} || do {
> 1283:           my $class =3D ref $_[0];
> 1284:           $_[0]->can('result_source_instance')
> 1285              ? $_[0]->result_source_instance
> 1286              : $_[0]->throw_exception(
> 1287                "No result source instance registered for $class, did
> you forget to call $class->table(...) ?"
> 1288              )
>   DB<24> x $_[0]
> 0  My::Test::Schema=3DHASH(0x18e93250)
>    'class_mappings' =3D> HASH(0x1895e7b0)
>       'My::Test::Schema::Node' =3D> 'Node'
>    'source_registrations' =3D> HASH(0x185b9280)
>       'Node' =3D> DBIx::Class::ResultSource::Table=3DHASH(0x17f39ed0)
>          '_columns' =3D> HASH(0x18e45620)
>             'active' =3D> HASH(0x185f2b60)
>                  empty hash
>             'display_name' =3D> HASH(0x185f2820)
>                  empty hash
>             'fqdn' =3D> HASH(0x185f2760)
>                  empty hash
>             'hostname' =3D> HASH(0x185f27b0)
>                  empty hash
>             'id' =3D> HASH(0x185f2900)
>                  empty hash
>             'ipv4' =3D> HASH(0x185f2b40)
>                  empty hash
>             'outbound_ipv4' =3D> HASH(0x185f27f0)
>                  empty hash
>             'role' =3D> HASH(0x185f2b30)
>                  empty hash
>          '_columns_info_loaded' =3D> 0
>          '_ordered_columns' =3D> ARRAY(0x18e456a0)
>             0  'id'
>             1  'ipv4'
>             2  'outbound_ipv4'
>             3  'hostname'
>             4  'fqdn'
>             5  'display_name'
>             6  'role'
>             7  'active'
>          '_primaries' =3D> ARRAY(0x183b55c0)
>             0  'id'
>          '_relationships' =3D> HASH(0x17f3a710)
>               empty hash
>          '_unique_constraints' =3D> HASH(0x183b62f0)
>             'primary' =3D> ARRAY(0x183b55c0)
>                -> REUSED_ADDRESS
>          'name' =3D> 'nodes'
>          'result_class' =3D> 'My::Test::Schema::Node'
>          'resultset_attributes' =3D> HASH(0x18e45230)
>               empty hash
>          'resultset_class' =3D> 'DBIx::Class::ResultSet'
>          'schema' =3D> My::Test::Schema=3DHASH(0x18e93250)
>             -> REUSED_ADDRESS
>          'source_name' =3D> 'Node'
>          'sqlt_deploy_callback' =3D> 'default_sqlt_deploy_hook'
>    'storage' =3D> DBIx::Class::Storage::DBI::mysql=3DHASH(0x17f3a550)
>       '_connect_info' =3D> ARRAY(0x1806f1a0)
>          0  'dbi:mysql:db:db.test.com'
>          1  'user'
>          2  'secret'
>          3  HASH(0x188f7b00)
>               empty hash
>       '_dbh' =3D> undef
>       '_dbh_details' =3D> HASH(0x1942c6d0)
>            empty hash
>       '_dbh_gen' =3D> 0
>       '_dbi_connect_info' =3D> ARRAY(0x18f6a2d0)
>          0  'dbi:mysql:db:db.test.com'
>          1  'user'
>          2  'secret'
>          3  HASH(0x18f6fd20)
>             'AutoCommit' =3D> 1
>             'PrintError' =3D> 0
>             'RaiseError' =3D> 1
>             'ShowErrorStatement' =3D> 1
>       '_dbic_connect_attributes' =3D> HASH(0x18f6fd20)
>          -> REUSED_ADDRESS
>       '_driver_determined' =3D> 1
>       '_in_determine_driver' =3D> undef
>       '_in_do_block' =3D> 0
>       '_sql_maker' =3D> DBIx::Class::SQLMaker::MySQL=3DHASH(0x191cc600)
>          'array_datatypes' =3D> 1
>          'bindtype' =3D> 'columns'
>          'cmp' =3D> '=3D'
>          'equality_op' =3D> Regexp=3DSCALAR(0x194069f0)
>             -> qr/(?i-xsm:^(\=3D|is|(is\s+)?like)$)/
>          'inequality_op' =3D> Regexp=3DSCALAR(0x1942c6e0)
>             -> qr/(?i-xsm:^(!=3D|<>|(is\s+)?not(\s+like)?)$)/
>          'injection_guard' =3D> Regexp=3DSCALAR(0x19406aa0)
>             -> qr/(?mix-s:
>     ;
>       |
>     ^ \s* go \s
>   )/
>          'limit_dialect' =3D> 'LimitXY'
>          'logic' =3D> 'OR'
>          'name_sep' =3D> '.'
>          'special_ops' =3D> ARRAY(0x19406ba0)
>             0  HASH(0x18bce330)
>                'handler' =3D> '_where_field_BETWEEN'
>                'regex' =3D> Regexp=3DSCALAR(0x18bcda70)
>                   -> qr/(?ix-sm:^ (?: not \s )? between $)/
>             1  HASH(0x191aac40)
>                'handler' =3D> '_where_field_IN'
>                'regex' =3D> Regexp=3DSCALAR(0x191ccb90)
>                   -> qr/(?ix-sm:^ (?: not \s )? in      $)/
>             2  HASH(0x18588590)
>                'handler' =3D> '_where_op_IDENT'
>                'regex' =3D> Regexp=3DSCALAR(0x1820a6f0)
>                   -> qr/(?ix-sm:^ ident $)/
>             3  HASH(0x19406950)
>                'handler' =3D> '_where_op_VALUE'
>                'regex' =3D> Regexp=3DSCALAR(0x1942c640)
>                   -> qr/(?ix-sm:^ value $)/
>          'sqlfalse' =3D> '0=3D1'
>          'sqltrue' =3D> '1=3D1'
>          'unary_ops' =3D> ARRAY(0x19406a60)
>             0  HASH(0x191a2130)
>                'handler' =3D> '_where_op_ANDOR'
>                'regex' =3D> Regexp=3DSCALAR(0x18bcdf10)
>                   -> qr/(?ix-sm:^ and  (?: [_\s]? \d+ )? $)/
>             1  HASH(0x191f06f0)
>                'handler' =3D> '_where_op_ANDOR'
>                'regex' =3D> Regexp=3DSCALAR(0x18bcdd00)
>                   -> qr/(?ix-sm:^ or   (?: [_\s]? \d+ )? $)/
>             2  HASH(0x191d9d50)
>                'handler' =3D> '_where_op_NEST'
>                'regex' =3D> Regexp=3DSCALAR(0x18bce0d0)
>                   -> qr/(?ix-sm:^ nest (?: [_\s]? \d+ )? $)/
>             3  HASH(0x18bce280)
>                'handler' =3D> '_where_op_BOOL'
>                'regex' =3D> Regexp=3DSCALAR(0x18bcd8c0)
>                   -> qr/(?ix-sm:^ (?: not \s )? bool     $)/
>             4  HASH(0x18588590)
>                -> REUSED_ADDRESS
>             5  HASH(0x19406950)
>                -> REUSED_ADDRESS
>       '_sql_maker_opts' =3D> HASH(0x18f628a0)
>            empty hash
>       'savepoints' =3D> ARRAY(0x17f3a750)
>            empty array
>       'schema' =3D> My::Test::Schema=3DHASH(0x18e93250)
>          -> REUSED_ADDRESS
>       'transaction_depth' =3D> 0
>   DB<25> x $_[0]->{result_source}
> 0  undef
>   DB<26> v
> 1286              : $_[0]->throw_exception(
> 1287                "No result source instance registered for $class, did
> you forget to call $class->table(...) ?"
> 1288              )
> 1289          }
> 1290      ;
> 1291    }
>
> Thanks in advance,
> Doug
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120628/3c7=
be9ff/attachment-0001.htm


More information about the DBIx-Class mailing list