0

I have script using Coro, Coro::LWP and LWP::UserAgent. I make an array of requests and run them by Coro's async {}. Then i use results from them and save to file. Script runs for hours or sometimes for minutes and then freezes. I've made a strace lookup to se what is it doing. There's a bunch of actions but after saving results there was this actions before the freeze:

rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({1211417888, 0}, {1211354002, 168413065}) = ? ERESTART_RESTARTBLOCK (To be restarted)
--- SIGWINCH (Window changed) @ 0 (0) ---
restart_syscall(<... resuming interrupted call ...>) = ? ERESTART_RESTARTBLOCK (To be restarted)
--- SIGWINCH (Window changed) @ 0 (0) ---
restart_syscall(<... resuming interrupted call ...>

Is there something strange of making sense of freezes?

Crossposted at PerlMonks.

Resolved: it was a strange usleep with very big ammount of seconds (like for 4000 days).

Community
  • 1
  • 1
elgato
  • 321
  • 3
  • 13
  • You could try [LWP::Protocol::Coro::http](http://search.cpan.org/perldoc?LWP::Protocol::Coro::http) instead of [Coro::LWP](http://search.cpan.org/perldoc?Coro::LWP) (which is a bit hackish). But that's taking at face value that this has something to do with LWP side of things. – ikegami Aug 28 '12 at 06:56
  • According to strace program ends all requests and finishes working with requests' results. It surely exited the async's join command and gone further. – elgato Aug 28 '12 at 07:08
  • After some talk with unix guys, seem i have usleep with very big ammount of time and script just sleeps for very very logs. Maybe an error in my sleep time calculations:( – elgato Aug 28 '12 at 08:18

1 Answers1

0

Coro is a co-operative multitasking library, so coroutines must explicitly yield control to the scheduler. Your call to sleep/usleep blocks the whole Perl process and prevents other code from being run; in this case you can perform a 'non-blocking' sleep that only blocks your current coroutine:

use Coro;
use AnyEvent;
...
Coro::AnyEvent::sleep 5;

Unless you absolutely need LWP's interface, btw, I highly recommend switching to AnyEvent::HTTP. Coro::LWP is a bit of a hack, it's highly sensitive to LWP internals and prone to freezing. AnyEvent::HTTP resolved several issues I had with my program locking up, and also offered better control over SSL cert validation and use of proxies, including socks proxies. It just a nicer, more featureful module overall.

rjh
  • 49,276
  • 4
  • 56
  • 63