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

Abnormal exit with threads, LWP and the Perl Debugger

by chrestomanci (Priest)
on Jan 20, 2012 at 11:55 UTC ( #948945=perlquestion: print w/ replies, xml ) Need Help??
chrestomanci has asked for the wisdom of the Perl Monks concerning the following question:

Greeting wise brothers.

I am experiencing a problem debugging code that uses threads and LWP::UserAgent. I have reduced my failing code to this snippet:

#!/usr/bin/perl # Setup Pragmas. use strict; use warnings; use threads; use HTTP::Request; use LWP::UserAgent; sub main () { print "Starting a thread to find all SHAs \n"; threads->create( sub{ findAndQ_sha() } )->detach(); print "This line should be reached without error messages.\n"; return 0; } sub findAndQ_sha { print "Worker thread findAndQ_sha() running.\n"; sleep 1_000_000_000; # For testing, sleep for a long time. return; } exit main();

If in the debugger, I attempt to step over the line where the thread is created, I get an error: Thread 1 terminated abnormally: Undefined subroutine &Devel::CLONE called at demoLWP_threadBug.pl line 13. and a breakpoint in the findAndQ_sha() function is not reached. If I run without the debugger the script runs normally.

I am testing with perl 5.12.4 on Ubuntu Oneiric Linux, AMD64

If I comment out the use HTTP::Request; and use LWP::UserAgent; lines, then the code runs correctly in the debugger.

The script I am working on is using a Thread_pool design pattern. One thread is created to populate a queue of URLs that need fetching and processing, and a number of other worker threads are created to read from the queue and process each URL in turn. In the full (non reduced) version of the script, the package where the undefined CLONE subroutine was searched for varies.

Can anyone shed any light on this problem? is it a bug in LWP?

Comment on Abnormal exit with threads, LWP and the Perl Debugger
Select or Download Code
Re: Abnormal exit with threads, LWP and the Perl Debugger
by Anonymous Monk on Jan 20, 2012 at 12:19 UTC

    is it a bug in LWP?

    I doubt it, it is more likely a bug in the debugger

Re: Abnormal exit with threads, LWP and the Perl Debugger
by BrowserUk (Pope) on Jan 27, 2012 at 11:11 UTC

    Did you get any resolution to this problem?

    I don't have anything to offer -- I haven't had a debugger that worked with threads for many builds; but then I didn't find it useful when it did work -- but I'd be interested to know what if any progress you've made?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      No, I did not get a resolution.

      At the moment I am using a work around where if I want to debug the parts of the code that do http requests I run a single threaded version of the script, and if I want to debug the threading stuff, I comment out the http stuff and replace it with dummy placeholder code.

      It would be nice to know where the bug lies so that I can report it to the correct place, though seeing as LWP is core, perhaps I should just report it as a bug against perl, and not concern myself with which module is to blame.

        Perhaps the simplest workaround -- and potentially quick way to trace the origin -- would be to satisfy the missing call:

        ## somewhere at the top of your application. BEGIN { package Devel; use Carp qw[ cluck ]; sub CLONE { cluck "Devel::CLONE called with args [ @_ ]"; } }

        That ought to both get you passed the symptom and provide a full trace-back to the originating cause.

        You might have to experiment with return values to prevent some error action being taken.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

      I have tested again using the recent perl 5.15.7 release (Locally compiled with perlbrew), and the bug has disappeared, so it looks like someone else has found and fixed it.

        and the bug has disappeared, so it looks like someone else has found and fixed it.

        or it just moved to some other bit of memory

        I'd still be interested to see the traceback from the call to Devel::CLONE. it might shed some light on why when I try to run your sample above under the debugger, it segfaults before it ever reached the DB prompt.

        It would also be nice to track the cure of the bug back to the change that fixed it to give us a more sure feeling that it has been fixed and not just moved,


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://948945]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (13)
As of 2014-07-28 19:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (207 votes), past polls