Skip to content

Instantly share code, notes, and snippets.

@marioroy
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marioroy/262ae81b1f5c4a7479ac to your computer and use it in GitHub Desktop.
Save marioroy/262ae81b1f5c4a7479ac to your computer and use it in GitHub Desktop.
test_results_Net-DNS-Native-0.11 running with threads hangs, ok with 0.10
# Script segfaults on CentOS 7 (Perl 5.16.3)
# Mojolicious 5.59, Net::DNS::Native 0.11
# Ok with Net::DNS::Native 0.10
# Create input file with 2 URLs
# http://wiki.qemu.org/Main_Page
# http://www.slashdot.org
#
# ./mce_threads.pl < input
BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}
use threads;
use Mojo::Base -strict;
use Mojo::UserAgent;
use Mojo::IOLoop;
use MCE::Loop;
MCE::Loop::init {
max_workers => 5, chunk_size => 40, user_begin => sub {
use vars qw( $ua );
our $ua = Mojo::UserAgent->new(
connect_timeout => 10, request_timeout => 30, max_redirects => 2
);
$ua->transactor->name('Mozilla/8.0');
}
};
mce_loop {
my ($mce, $chunk_ref, $chunk_id) = @_;
chomp @$chunk_ref;
Mojo::IOLoop->delay(
sub {
my $delay = shift;
foreach my $url (@$chunk_ref) {
$ua->get($url => $delay->begin);
}
},
sub {
my ($delay, @args) = @_;
foreach my $tx (@args) {
my $url = $tx->req->url;
if ($tx->res->error) {
MCE->say("$url 0 :: " . $tx->res->error->{message});
} else {
MCE->say("$url " . length $tx->res->body);
}
}
}
)->wait;
} <>;
MCE::Loop::finish;
# Script hangs on CentOS 7 (Perl 5.16.3); Requires kill -9 <pid>
# Mojolicious 5.59, Net::DNS::Native 0.11
# Ok with Net::DNS::Native 0.10
BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}
use threads;
use Mojo::Base -strict;
use Mojo::UserAgent;
use Mojo::IOLoop;
sub thrsub {
my ($url) = @_;
my $ua = Mojo::UserAgent->new(
connect_timeout => 10, request_timeout => 30, max_redirects => 2
);
$ua->transactor->name('Mozilla/8.0');
Mojo::IOLoop->delay(
sub {
my $delay = shift;
$ua->get($url => $delay->begin);
},
sub {
my ($delay, @args) = @_;
foreach my $tx (@args) {
my $url = $tx->req->url;
if ($tx->res->error) {
say "$url 0 :: " . $tx->res->error->{message};
} else {
say "$url " . length $tx->res->body;
}
}
}
)->wait;
}
my $thr1 = threads->create(\&thrsub, 'http://wiki.qemu.org/Main_Page');
my $thr2 = threads->create(\&thrsub, 'http://www.slashdot.org');
$thr1->join();
$thr2->join();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment