Upgrade to Pro — share decks privately, control downloads, hide ads and more …

debug-perl

 debug-perl

2015.06.02 shibuya.pm LT

Shoichi Kaji

June 02, 2015
Tweet

More Decks by Shoichi Kaji

Other Decks in Technology

Transcript

  1. ໨࣍ ͋ΔbugΛௐࠪͨ͠ͱ͖ͷ࿩ • 1. ͲΜͳ bug ͔ • prefork ܕͷ

    worker ͕਺೔ܦͭͱݻ·Δ • 2. gdb Ͱ backtrace දࣔ • 3. safe / unsafe signals • 4. ·ͱΊ
  2. 1. bug: program https://github.com/shoichikaji/perl-hang package Worker { use Sys::SigAction ‘timeout_call’;

    sub work { my $self = shift; timeout_call 3, sub { heavy_work() } } } my $pm = Parallel::Prefork->new( max_workers => 30, trap_signals => {TERM => ‘TERM’} ); while ($pm->signal_received ne 'TERM') { $pm->start and next; Worker->work; $pm->finish; } $pm->wait_all_children;
  3. 1. bug: worker͕ݻ·Δ > ps auxwwf | less -S Apr1

    0:03 | \_ perl program.pl Apr5 0:00 | \_ perl program.pl <- ௕ظؒੜଘɺݻ·ͬͯΔ 12:33 0:02 | \_ perl program.pl 12:33 0:01 | \_ perl program.pl 12:33 0:01 | \_ perl program.pl
  4. 2. gdb backtrace > gdb -p $PID (gdb) bt #0

    0x00007fb96b78e05e in __lll_lock_wait_private () from /lib64/libc.so.6 #1 0x00007fb96b71316b in _L_lock_9503 () from /lib64/libc.so.6 #2 0x00007fb96b7106a6 in malloc () from /lib64/libc.so.6 #3 0x000000000048a675 in Perl_safesysmalloc (size=<value optimi..>) #4 0x00000000004b7a28 in Perl_sv_grow (sv=0x16347b0, newlen=10) #5 0x00000000004b4968 in Perl_sv_setsv_flags (dstr=0x16347b0,..) #6 0x00000000004b56bd in Perl_newSVsv (old=<value opt..) #7 0x0000000000494ff2 in Perl_sighandler (sig=14, sip=0x7fff0..) #8 <signal handler called> #9 0x00007fb96b70f17d in _int_malloc () from /lib64/libc.so.6 #10 0x00007fb96b7106b1 in malloc () from /lib64/libc.so.6 —-> SIGALRM(sig=14)ͷॲཧͰࢭ·͍ͬͯΔ
  5. 3. safe/unsafe signals • perlipc ʹΑΔͱ • safe signal (σϑΥϧτ)

    • perl interpreter ͕҆શͳͱ͖ʹsignal handlingΛ͢Δɻ
 ҆શ͕ͩCϨϕϧͷؔ਺ʹׂͬͯೖΕͳ͍ɻ • unsafe signal (via POSIX::sigaction) • CϨϕϧͷؔ਺ʹׂͬͯೖΕΔɻ
 ͔͠͠memoryഁյɺؔ਺࠶࣮ߦͳͲͷ͓ͦΕ͋Γɻ
  6. 3. safe/unsafe signals • safe signal - CϨϕϧͷؔ਺ʹׂͬͯೖΕͳ͍ • Լه͸

    timeout ͠ͳ͍ɻhttps://github.com/shoichikaji/safa-unsafe-signal • unsafe signal - ҆શͰͳ͍ • worker ͕ݻ·Δͷ͸͜Ε͕ݪҼ (?)
  7. ·ͱΊ • perl ʹ͸ safe / unsafe signal ͕͋Δ •

    safeγάφϧ͸ड͚औΕͳ͍ͱ͖͕͋Δ • unsafeγάφϧ͸memoryഁյͳͲΛى͜͢ͱ͖͕͋Δ • safe/unsafe Ұ௕Ұ୹ɻͪΌΜͱߟྀͯ͠࢖͏΂͖ • ஫: debugʹඋ͑ͯperl͸-g͖ͭͰ build ͢΂͖