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

Hi,

I am using following modules in a thread based script:

use threads; use threads::shared; use Thread::Queue; use Text::CSV_XS; use SOAP::Lite; use XML::Twig; use Config::IniFiles; use Tie::File; uname -a Linux c2t17958.xxxx.xxxx.net 2.6.32-642.11.1.el6.x86_64 #1 SMP Wed Oct + 26 10:25:23 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux

I get the following error sometimes:

"*** glibc detected *** perl: double free or corruption (!prev): 0x000 +07f9594461ca0 ***"

and sometimes script dies without showing any errors.

Can anyone suggest solution or help in debugging the issue?

Script works as expected most of the time. Problem occurs vary rarely. Still it is a serious problem

Replies are listed 'Best First'.
Re: Problem with script using threads
by choroba (Cardinal) on May 09, 2017 at 11:25 UTC
    Are the used modules thread safe? Are they being used in more than one thread?

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: Problem with script using threads
by Anonymous Monk on May 09, 2017 at 21:54 UTC

    Hi,

    This is how you do threads, you separate the main thread modules from the worker thread modules

    #!/usr/bin/perl -- use strict; use warnings; use threads stack_size => 4096; use Thread::Queue; Main( @ARGV ); exit( 0 ); sub Main { my $q = Threads::Queue->new; ... } sub Worker { require Text::CSV_XS; require SOAP::Lite; require XML::Twig; require Config::IniFiles; require Tie::File; ... }

      Update: It is throwing memory fault when run with more then 1 thread. If thread count = 1 then the script executes properly

        :)

        Where is the minimal code needed to reproduce the error?

      Let me try this and let you know. Thanks
        This did not help resolving my problem. Update: I moved the same script to HP-UX server.I am getting memory fault error. any suggestions? OS:uname -a HP-UX xxxxxxx B.11.31 U ia64 2666145408 unlimited-user license
Re: Problem with script using threads
by oiskuu (Hermit) on May 11, 2017 at 16:56 UTC

    How deep do you want to go and what tools do you have available?

    One option to track down malloc bugs is to use valgrind --tool=memcheck. But it will greatly help to have a proper debug build with symbols and the sources unpacked, too. In which case you could instead try the sanitizers that come with modern compiler toolchains. Perl should properly build and run with either ASAN or TSAN (address or thread sanitizer). For example.

    $ export ASAN_OPTIONS=detect_leaks=0      # ignore exit leaks
    $ cd perl-5.24.1
    $ ./Configure -des -Dprefix=/tmp/TEST -Dusethreads -DDEBUGGING \
      -Dcc='clang -fPIE -fsanitize=address -fno-optimize-sibling-calls -fno-omit-frame-pointer'
    $ make -j5 && make install
    $ PATH="/tmp/TEST/bin:$PATH"
    ... # build and install modules
    
    The sanitizers have significant run-time memory and cpu overheads. More about them at github.

      I hardly have any tool to debug. No much permission to do anything with machine. when i tried "file core" of coredump I got the following: core: ELF-32 core file - IA64 from 'perl-dynamic' - received SIGSEGV