nikosv has asked for the wisdom of the Perl Monks concerning the following question:

(cross-posted at the dancer.pm mail list http://lists.preshweb.co.uk/pipermail/dancer-users/2015-April/004537.html)

I'm building a site and it's all fine and well except when randomly getting part of the page (without any css,html) essentially like a semi-half blank page and ,sometimes again, getting a "Reload the page to get source for:" from the GET request using Firebug. Firebug's Net panels shows only the initial GET request but not the subsequent ones to the other resources, like the CSS file, images,Javascripts etc

When that happens I get the following in the DBI trace log :

<-- dbd_st_finish 1 <- fetch= ( undef ) [1 items] row1 at /home/starman/perl5/perlbrew +/perls/perl-5.18.1/lib/site_perl/5.18.1/x86_64-linux/DBD/mysql.pm lin +e 867 via at /home/starman/Foo/bin/../lib/MySite/Model.pm line 219 <- fetchrow_hashref= ( undef ) [1 items] row1 at /home/starman/Foo +/bin/../lib/MySite/Model.pm line 219 via at /home/starman/Foo/bin/.. +/lib/Foo.pm line 34 <> DESTROY(DBI::st=HASH(0x3fcfc60)) ignored for outer handle (inne +r DBI::st=HASH(0x3fcfac8) has ref cnt 1) -> DESTROY for DBD::mysql::st (DBI::st=HASH(0x3fcfac8)~INNER) <- DESTROY= ( undef ) [1 items] at /home/starman/Foo/bin/../lib/Fo +o.pm line 34 via at /home/starman/Foo/bin/../lib/Foo.pm line 34 DESTROY (dbih_clearcom) (sth 0x3fcfac8, com 0x41e4d70, imp DBD::my +sql::st): FLAGS 0x180191: COMSET Warn RaiseError PrintError PrintWarn PARENT DBI::db=HASH(0x3d23dc0) KIDS 0 (0 Active) NUM_OF_FIELDS 38 NUM_OF_PARAMS 0 dbih_clearcom 0x3fcfac8 (com 0x41e4d70, type 3) done. <> DESTROY(DBI::db=HASH(0x3d18b00)) ignored for outer handle (inne +r DBI::db=HASH(0x3d23dc0) has ref cnt 1) -> DESTROY for DBD::mysql::db (DBI::db=HASH(0x3d23dc0)~INNER) imp_dbh->pmysql: 42d7440 <- DESTROY= ( undef ) [1 items] at /home/starman/Foo/bin/../lib/Fo +o.pm line 34 via at /home/starman/Foo/bin/../lib/Foo.pm line 34 DESTROY (dbih_clearcom) (dbh 0x3d23dc0, com 0x418e4e0, imp DBD::my +sql::db): FLAGS 0x180391: COMSET Warn RaiseError PrintError PrintWarn Aut +oCommit PARENT DBI::dr=HASH(0x3c85940) KIDS 0 (0 Active) IMP_DATA HASH(0x3d23478) dbih_clearcom 0x3d23dc0 (com 0x418e4e0, type 2) done.

I should explain more:
there are two queries each one in its own sub, the first one being called through a straightforward [% PROCESS tablets.tt %] which populates some elements like drop down select menus,sliders etc

When the user makes a choice the second query is fired through an Ajax call:

$.ajax({ url: '/query2', type: "POST", data: AllData(1)}).success(function(data){ $("#contentx").append(data); });
which populates a #contentx div with the results of the query.

Now,when in the same session, the error does not occur no matter how much I stress it. When opening another 4-5 sessions,or doing a couple of reloads of the same session, the DBI error comes up and I get the effect of the first query being run as the elements are still populated, but then there is nothing else:no css,scripts,and the rest of the html code .

Is that indicating a global DBI handle that is reused and cleaned up at some time,having to do with Starman's preforking? The thing is that in my Model I initialize the database and statement handles within the subs scope and not globally.
Any help deeply appreciated,thanks!

The setup is Dancer,Starman,Mysql on Digital Ocean
DBD:mysql 4.031
DBI 1.633
Dancer2 0.158000
Ubuntu 14.04 x86_64 x86_64 x86_64 GNU/Linux

Replies are listed 'Best First'.
Re: random web page breakages (Dancer2)
by Corion (Patriarch) on Apr 26, 2015 at 20:53 UTC

    Have you checked whether Dancer2 is part of the problem at all? I would try to reproduce the problem with Starman and DBI alone.

    A most likely culprit is fork and DBI not playing well (enough) together.

    Maybe (maybe) you can reset the database connection when a child is forked off in Starman. I don't know if/how Dancer gets in the way here, so first I would try to get Starman and DBI working and then see if/how Dancer2::DBI needs further changes.

Re: random web page breakages (Dancer2)
by Anonymous Monk on Apr 26, 2015 at 20:39 UTC
    so you're sharing javascript snippets?