Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Segmentation fault in DBI + XML::LibXML

by furagu (Initiate)
on Feb 01, 2012 at 16:52 UTC ( #951269=perlquestion: print w/replies, xml ) Need Help??
furagu has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

I have a very strange problem, my code produces a segmentation fault. Here is the sample code to reproduce the problem:

#!/usr/bin/perl use DBI; use XML::LibXML; my $dbh = DBI->connect('DBI:Pg:dbname=mydb', 'user', 'password'); or die $DBI::errstr;

And the output is

Segmentation fault: 11 (core dumped)

I've figured that commenting out "use XML::LibXML;" makes the code work. Have no idea of what's going on :(

I have perl 5.10.1 under amd64-freebsd 8.0
The libraries are the latest versions installed from ports:
XML::LibXML 1.88,1
DBI 1.617
DBD::Pg 2.18.1_1
libxml2 2.7.8_1

Can somebody help me with this weird problem?

Replies are listed 'Best First'.
Re: Segmentation fault in DBI + XML::LibXML
by perl514 (Pilgrim) on Feb 01, 2012 at 19:02 UTC


    Is this the only script where you are noticing this issue? Try creating another script only with the LibXML module and see if it dumps core. Also, more importantly, use the  use warnings and  use strict at the beginning of the script. This could give you some warnings while you try to run the script that may give you some direction.

    Also go through this article which may help you.

    I am in the process of installing FreeBSD 9.0 on my personal laptop (Been toying around with a few Linux flavours but now thinking of FreeBSD) and would try out your script on that once done, but till then, please try out my suggestions


    Perlpetually Indebted To PerlMonks

      Hi perl514, thanks for reply.

      This is not the only script that fails, all of my scripts that somehow use both LibXML and DBI libraries (even in different packages) are segfaulting after newest libxml and dbi libraries installation :(

      Warnings and strict showed nothing.

      XML::LibXML alone works as usual, and the DBI alone works too.

      Now I'm stuck trying to rebuild postgresql-client without threading support. This is not an easy task as 'enable-thread-safety' option is not configurable with 'make config' and is turned on by default.

Re: Segmentation fault in DBI + XML::LibXML
by mje (Curate) on Feb 02, 2012 at 08:14 UTC

    Run gdb /usr/bin/perl and at the gdb prompt "r" then enter. When it seg faults use the back trace command (bt) to see where it fell over and post it here. Someone might recognise the function it falls over in. It is quite possible the XML and postgres libraries both contain the same symbol for a function but take different arguments. When that function is called it will sometimes (depending on how everything is linked) only get resolved in one place so one of the calls will be wrong. You can get a list of symbols in the postgres and libxml libraries using nm if that is the case or when you get the back trace you can check for that symbol in each library to rule that in/out.

Re: Segmentation fault in DBI + XML::LibXML
by furagu (Initiate) on Feb 05, 2012 at 17:39 UTC

    Finally I got the solution.

    Following advice from mje I ran the script in debugger and got this trace:

    #0 0x000000080283d92d in pthread_mutex_destroy () from /lib/ +.3 #1 0x0000000801a15a15 in xmlFreeMutex () from /usr/local/lib/libxml2. +so.5 #2 0x0000000801a15455 in xmlCleanupGlobals () from /usr/local/lib/lib #3 0x00000008019ade8a in xmlCleanupParser () from /usr/local/lib/libx #4 0x000000080184edb3 in XS_XML__LibXML_END () from /usr/local/lib/pe +rl5/site_perl/5.10.1/mach/auto/XML/LibXML/ #5 0x00000008006df1f4 in Perl_pp_entersub () from /usr/local/lib/perl +5/5.10.1/mach/CORE/ #6 0x000000080068c0b0 in Perl_call_sv () from /usr/local/lib/perl5/5. +10.1/mach/CORE/ #7 0x000000080068c3c3 in Perl_call_list () from /usr/local/lib/perl5/ +5.10.1/mach/CORE/ #8 0x000000080068fe5f in perl_destruct () from /usr/local/lib/perl5/5 +.10.1/mach/CORE/ #9 0x0000000000400bcc in main ()

    Seems like the problem is related to a thread support (this is also stated in the article posted by perl514).

    Postgresql-client library has a thread safety turned on by default, so it took me some time to get it built without thread safety support, and that worked.

    I don't think this is a really good solution though because thread safety can be usefull, and the best way would be to fix the libxml. But my scripts do not use threads, so I'm safe :)

    Here are some short instructions how to rebuild postgresql-client without thread safety for those who's having the same problem.

    First, configure postgresql-client port to get config.log file created:

    cd /usr/ports/databases/postgresql84-client/; make configure

    Second, extract configure options set by ports system:

    cd work/postgresql-8.4.10/; grep ./configure config.log

    There'll be something like this:

    ./configure --with-libraries=/usr/local/lib --with-includes=/usr/local/include --enable-thread-safety --with-openssl --with-libxml --enable-integer-datetimes --enable-nls --without-gssapi --prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/info/ --build=amd64-portbld-freebsd8.2

    Remove '--enable-thread-safety' from configure command line and run it in the current dir.

    After the library is configured, build and reinstall it the usual way:

    cd ../../; make FORCE_PKG_REGISTER=1 reinstall clean

    That's all, now the postgresql-client has no thread safety.

    Thanks to perl514, mje and Anonymous Monk for suggestions!

Re: Segmentation fault in DBI + XML::LibXML
by Anonymous Monk on Feb 02, 2012 at 03:05 UTC
    Try upgrading perl (say a supported version like 5.12.2, soon to be unsupported). See]

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://951269]
Approved by Marshall
[shmem]: No, not coincidence - prejudice and bias
[shmem]: your scanner is pre-loaded ;-)
[shmem]: anyways, do as is your wont. I won't fight western hypocresy anymore - for today. Let's call that a day, and done.
[erix]: yeah, scanning pre-loaded. I wouldn't have it any other way. As I say, my attention is a rare commodity, jealously guarded.
[erix]: ok, ok. happy pipe-dreams :P

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2018-03-19 21:10 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.