»ö« #raku and #raku-dev are OPEN FOR BUSINESS | perl6.org/ | evalbot usage: 'p6: say 3;' or /msg camelia p6: ... | irclog: irc.perl6.org or colabti.org/irclogger/irclogger_log/perl6 | UTF-8 is our friend! 🦋
Set by mst on 15 October 2019.
mst Grinnz: perigrin 02:18
DavidHoloshka Class variable usage causing seg fault on ubuntu in cro ? 14:25
jnthn Code example reproducing it? 14:28
timotimo could you be using (adding to or removing from) hashes concurrently by accident? 14:28
jnthn Could be
Cro distributes requests across threads, and if things aren't protected appropriately, it won't end well (that it segvs is a bug, but still, it's not expected to magically behave) 14:29
DavidHoloshka I am trying to create a persistent db and file handle across instantiations of classes using a Class variable. Not saying this is a bug. The fault happens in perl6. 14:31
class kohaStatusChecker::KohaDatabaseAccessor { use DBIish; use Config; my $dbish; my $kohaConfig; # establish a connection to the database save it in a Class variable (not an instance var) method connect( ) { # Read the configuration file and assign values to the member variables if ! $kohaConfig { 14:32
$kohaConfig = Config.new(); $kohaConfig.read("/etc/kohaStatusChecker/config.yaml"); } # connect to db if ! $dbish { my $aHost = $kohaConfig<DB_HOST>; my $aDb = $kohaConfig<DB_NAME>; my $aUser = $kohaConfig<DB_USER>; my $password = $kohaConfig<DB_PASS>; $dbish =
DBIish.connect('mysql', :host($aHost), :port($kohaConfig<DB_PORT>), :database($aDb), :user($aUser), :$password, :PrintError); } }
jnthn Hmm, that's at the very least racey, if two things call connect. 14:37
I'd `use OO::Monitors`, s/class/monitor/, promote the class variables to instance ones, and then do the singleton pattern along the lines of `my $instance = INIT kohaStatusChecker::KohaDatabaseAccessor.new; method get-instance() { $instance }` or some such. 14:39
Alternatively, you might like to check out the module DB::MySQL, which I *think* does a connection pool for you :) 14:40
The docs match that; modules.raku.org/dist/DB::MySQL:cpan:CTILMES
Also the DB::foo modules in my experience are higher quality than DBIish 14:41
tadzik heh, the docs mention DB::SQLite. They may have been copy-pasted... ;) 14:43
jnthn Oops :) 14:45
PR time!
DavidHoloshka ok thanks I will investigate these ideas 14:54