Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
removed support for non-blocking name resolution with Net::DNS::Nativ…
…e again, because there have been too many problems with segmentation faults (closes #716)
  • Loading branch information
kraih committed Dec 11, 2014
1 parent 9a5c2ce commit 3f7dc3f
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -9,7 +9,7 @@ perl:
env:
- "HARNESS_OPTIONS=j9 TEST_EV=1 TEST_IPV6=1 TEST_POD=1 TEST_SOCKS=1 TEST_TLS=1"
install:
- "cpanm -n EV IO::Socket::Socks IO::Socket::SSL Net::DNS::Native Test::Pod Test::Pod::Coverage"
- "cpanm -n EV IO::Socket::Socks IO::Socket::SSL Test::Pod Test::Pod::Coverage"
- "cpanm -n --installdeps ."
notifications:
email: false
9 changes: 5 additions & 4 deletions Changes
@@ -1,13 +1,14 @@

5.69 2014-12-11
5.69 2014-12-12
- Deprecated Mojo::DOM::siblings.
- Added following, following_siblings, preceding and preceding_siblings
methods to Mojo::DOM.
- Added port method to Mojo::IOLoop::Server.
- Removed support for non-blocking name resolution with Net::DNS::Native
again, because there have been too many problems with segmentation faults.
- Removed deprecated emit_safe method from Mojo::EventEmitter.
- Removed deprecated render_static method from Mojolicious::Controller.
- Removed deprecated has_conditions method from Mojolicious::Routes::Route.
- Updated Net::DNS::Native requirement to 0.13 for some important bug fixes.
- Improved Mojo::DOM::HTML performance slightly.
- Fixed parent combinator bug in Mojo::DOM::CSS.
- Fixed whitespace bug in Mojo::DOM::HTML.
Expand Down Expand Up @@ -3460,7 +3461,7 @@
- Added ".gitignore" generator command. (marcus)
- Added automatic CGI/FastCGI environment detection to Mojo::Commands.
- Renamed Mojolicious::Book to Mojolicious::Guides.
- Removed hot deployment support for Windows because of incompatibilities
- Removed hot deployment support for Windows, because of incompatibilities
between Active Perl and Strawberry Perl.
- Made process id and lock file defaults more user-friendly in
Mojo::Server::Daemon.
Expand Down Expand Up @@ -4112,7 +4113,7 @@
- Added workaround for missing IO::Seekable support in older versions of
File::Temp (Perl 5.8).
- script/mojo.pl got renamed to bin/mojo.
- Mojo::Cache got renamed to Mojo::File because there will be a cache
- Mojo::Cache got renamed to Mojo::File, because there will be a cache
module named MojoX::Cache, and that could cause confusion later on.
- Fixed many escaping related bugs around Mojo::URL.
- Fixed 100-Continue support in Mojo::Server::Daemon and Mojo::Client.
Expand Down
13 changes: 8 additions & 5 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -314,18 +314,21 @@ scalable C<select>.
LIBEV_FLAGS=4 # epoll (Linux)
LIBEV_FLAGS=8 # kqueue (*BSD, OS X)
Connections are established non-blocking, but name resolution needs to be
performed blocking, so you should reduce concurrency if resolver timeouts are
a possibility.
The event loop will be resilient to time jumps if a monotonic clock is
available through L<Time::HiRes>. A TLS certificate and key are also built
right in, to make writing test servers as easy as possible. Also note that for
convenience the C<PIPE> signal will be set to C<IGNORE> when L<Mojo::IOLoop>
is loaded.
For better scalability (epoll, kqueue) and to provide non-blocking name
resolution, SOCKS5 as well as TLS support, the optional modules L<EV> (4.0+),
L<Net::DNS::Native> (0.13+), L<IO::Socket::Socks> (0.64+) and
For better scalability (epoll, kqueue) and to provide SOCKS5 as well as TLS
support, the optional modules L<EV> (4.0+), L<IO::Socket::Socks> (0.64+) and
L<IO::Socket::SSL> (1.84+) will be used automatically if they are installed.
Individual features can also be disabled with the C<MOJO_NO_NDN>,
C<MOJO_NO_SOCKS> and C<MOJO_NO_TLS> environment variables.
Individual features can also be disabled with the C<MOJO_NO_SOCKS> and
C<MOJO_NO_TLS> environment variables.
See L<Mojolicious::Guides::Cookbook/"REAL-TIME WEB"> for more.
Expand Down
38 changes: 5 additions & 33 deletions lib/Mojo/IOLoop/Client.pm
Expand Up @@ -7,12 +7,6 @@ use Mojo::IOLoop;
use Scalar::Util 'weaken';
use Socket qw(IPPROTO_TCP TCP_NODELAY);

# Non-blocking name resolution requires Net::DNS::Native
use constant NDN => $ENV{MOJO_NO_NDN}
? 0
: eval 'use Net::DNS::Native 0.13 (); 1';
my $NDN = NDN ? Net::DNS::Native->new(pool => 5, extra_thread => 1) : undef;

# TLS support requires IO::Socket::SSL
use constant TLS => $ENV{MOJO_NO_TLS}
? 0
Expand Down Expand Up @@ -41,49 +35,28 @@ sub connect {
$self->{timer} = $reactor->timer($args->{timeout} || 10,
sub { $self->emit(error => 'Connect timeout') });

# Blocking name resolution
$_ && s/[[\]]//g for @$args{qw(address socks_address)};
my $address = $args->{socks_address} || ($args->{address} ||= 'localhost');
return $reactor->next_tick(sub { $self && $self->_connect($args) })
unless NDN && $address ne 'localhost' && !$args->{handle};

# Non-blocking name resolution
my $handle = $self->{dns}
= $NDN->getaddrinfo($address, _port($args), {protocol => IPPROTO_TCP});
$reactor->io(
$handle => sub {
my $reactor = shift;

$reactor->remove($self->{dns});
my ($err, @res) = $NDN->get_result(delete $self->{dns});
return $self->emit(error => "Can't resolve: $err") if $err;

$args->{addr_info} = \@res;
$self->_connect($args);
}
)->watch($handle, 1, 0);
$reactor->next_tick(sub { $self && $self->_connect($args) });
}

sub _cleanup {
my $self = shift;
return $self unless my $reactor = $self->reactor;
$NDN->timedout($self->{dns}) if $self->{dns};
$self->{$_} && $reactor->remove(delete $self->{$_}) for qw(dns timer handle);
$self->{$_} && $reactor->remove(delete $self->{$_}) for qw(timer handle);
return $self;
}

sub _connect {
my ($self, $args) = @_;

my $handle;
my $address = $args->{socks_address} || $args->{address};
my $address = $args->{socks_address} || ($args->{address} ||= 'localhost');
unless ($handle = $self->{handle} = $args->{handle}) {
my %options = (
Blocking => 0,
PeerAddr => $address eq 'localhost' ? '127.0.0.1' : $address,
PeerPort => _port($args)
);
%options = (PeerAddrInfo => $args->{addr_info}) if $args->{addr_info};
$options{Blocking} = 0;
$options{LocalAddr} = $args->{local_address} if $args->{local_address};
return $self->emit(error => "Can't connect: $@")
unless $self->{handle} = $handle = IO::Socket::IP->new(%options);
Expand Down Expand Up @@ -267,8 +240,7 @@ implements the following new ones.
$client->connect(address => '127.0.0.1', port => 3000);
Open a socket connection to a remote host. Note that non-blocking name
resolution depends on L<Net::DNS::Native> (0.13+) and TLS support on
Open a socket connection to a remote host. Note that TLS support depends on
L<IO::Socket::SSL> (1.84+).
These options are currently available:
Expand Down
9 changes: 4 additions & 5 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -264,12 +264,11 @@ L<Mojo::Server::Daemon> is a full featured, highly portable non-blocking I/O
HTTP and WebSocket server, with IPv6, TLS, Comet (long polling), keep-alive
and multiple event loop support.
For better scalability (epoll, kqueue) and to provide non-blocking name
resolution, SOCKS5 as well as TLS support, the optional modules L<EV> (4.0+),
L<Net::DNS::Native> (0.13+), L<IO::Socket::Socks> (0.64+) and
For better scalability (epoll, kqueue) and to provide SOCKS5 as well as TLS
support, the optional modules L<EV> (4.0+), L<IO::Socket::Socks> (0.64+) and
L<IO::Socket::SSL> (1.84+) will be used automatically if they are installed.
Individual features can also be disabled with the C<MOJO_NO_NDN>,
C<MOJO_NO_SOCKS> and C<MOJO_NO_TLS> environment variables.
Individual features can also be disabled with the C<MOJO_NO_SOCKS> and
C<MOJO_NO_TLS> environment variables.
See L<Mojolicious::Guides::Cookbook/"DEPLOYMENT"> for more.
Expand Down
9 changes: 4 additions & 5 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -172,12 +172,11 @@ You can run the same command again for automatic hot deployment.
This second invocation will load the application again, detect the process id
file with it, and send a L</"USR2"> signal to the already running server.
For better scalability (epoll, kqueue) and to provide non-blocking name
resolution, SOCKS5 as well as TLS support, the optional modules L<EV> (4.0+),
L<Net::DNS::Native> (0.13+), L<IO::Socket::Socks> (0.64+) and
For better scalability (epoll, kqueue) and to provide SOCKS5 as well as TLS
support, the optional modules L<EV> (4.0+), L<IO::Socket::Socks> (0.64+) and
L<IO::Socket::SSL> (1.84+) will be used automatically if they are installed.
Individual features can also be disabled with the C<MOJO_NO_NDN>,
C<MOJO_NO_SOCKS> and C<MOJO_NO_TLS> environment variables.
Individual features can also be disabled with the C<MOJO_NO_SOCKS> and
C<MOJO_NO_TLS> environment variables.
See L<Mojolicious::Guides::Cookbook/"DEPLOYMENT"> for more.
Expand Down
9 changes: 4 additions & 5 deletions lib/Mojo/Server/Morbo.pm
Expand Up @@ -130,12 +130,11 @@ To start applications with it you can use the L<morbo> script.
$ morbo ./myapp.pl
Server available at http://127.0.0.1:3000.
For better scalability (epoll, kqueue) and to provide non-blocking name
resolution, SOCKS5 as well as TLS support, the optional modules L<EV> (4.0+),
L<Net::DNS::Native> (0.13+), L<IO::Socket::Socks> (0.64+) and
For better scalability (epoll, kqueue) and to provide SOCKS5 as well as TLS
support, the optional modules L<EV> (4.0+), L<IO::Socket::Socks> (0.64+) and
L<IO::Socket::SSL> (1.84+) will be used automatically if they are installed.
Individual features can also be disabled with the C<MOJO_NO_NDN>,
C<MOJO_NO_SOCKS> and C<MOJO_NO_TLS> environment variables.
Individual features can also be disabled with the C<MOJO_NO_SOCKS> and
C<MOJO_NO_TLS> environment variables.
See L<Mojolicious::Guides::Cookbook/"DEPLOYMENT"> for more.
Expand Down
9 changes: 4 additions & 5 deletions lib/Mojo/Server/Prefork.pm
Expand Up @@ -261,12 +261,11 @@ keep-alive and multiple event loop support. Note that the server uses signals
for process management, so you should avoid modifying signal handlers in your
applications.
For better scalability (epoll, kqueue) and to provide non-blocking name
resolution, SOCKS5 as well as TLS support, the optional modules L<EV> (4.0+),
L<Net::DNS::Native> (0.13+), L<IO::Socket::Socks> (0.64+) and
For better scalability (epoll, kqueue) and to provide SOCKS5 as well as TLS
support, the optional modules L<EV> (4.0+), L<IO::Socket::Socks> (0.64+) and
L<IO::Socket::SSL> (1.84+) will be used automatically if they are installed.
Individual features can also be disabled with the C<MOJO_NO_NDN>,
C<MOJO_NO_SOCKS> and C<MOJO_NO_TLS> environment variables.
Individual features can also be disabled with the C<MOJO_NO_SOCKS> and
C<MOJO_NO_TLS> environment variables.
See L<Mojolicious::Guides::Cookbook/"DEPLOYMENT"> for more.
Expand Down
9 changes: 4 additions & 5 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -440,12 +440,11 @@ All connections will be reset automatically if a new process has been forked,
this allows multiple processes to share the same L<Mojo::UserAgent> object
safely.
For better scalability (epoll, kqueue) and to provide non-blocking name
resolution, SOCKS5 as well as TLS support, the optional modules L<EV> (4.0+),
L<Net::DNS::Native> (0.13+), L<IO::Socket::Socks> (0.64+) and
For better scalability (epoll, kqueue) and to provide SOCKS5 as well as TLS
support, the optional modules L<EV> (4.0+), L<IO::Socket::Socks> (0.64+) and
L<IO::Socket::SSL> (1.84+) will be used automatically if they are installed.
Individual features can also be disabled with the C<MOJO_NO_NDN>,
C<MOJO_NO_SOCKS> and C<MOJO_NO_TLS> environment variables.
Individual features can also be disabled with the C<MOJO_NO_SOCKS> and
C<MOJO_NO_TLS> environment variables.
See L<Mojolicious::Guides::Cookbook/"USER AGENT"> for more.
Expand Down
2 changes: 0 additions & 2 deletions lib/Mojolicious/Command/version.pm
Expand Up @@ -15,7 +15,6 @@ sub run {
my $class = 'Mojo::IOLoop::Client';
my $socks = $class->SOCKS ? $IO::Socket::Socks::VERSION : 'not installed';
my $tls = $class->TLS ? $IO::Socket::SSL::VERSION : 'not installed';
my $ndn = $class->NDN ? $Net::DNS::Native::VERSION : 'not installed';

print <<EOF;
CORE
Expand All @@ -26,7 +25,6 @@ OPTIONAL
EV 4.0+ ($ev)
IO::Socket::Socks 0.64+ ($socks)
IO::Socket::SSL 1.84+ ($tls)
Net::DNS::Native 0.13+ ($ndn)
EOF

Expand Down
5 changes: 2 additions & 3 deletions lib/Mojolicious/Guides/FAQ.pod
Expand Up @@ -34,9 +34,8 @@ without compromises. While there are no rules in
L<Mojolicious::Guides::Contributing> that forbid dependencies, we do currently
discourage adding non-optional ones in favor of a faster and more painless
installation process. And we do in fact already use several optional CPAN
modules such as L<EV>, L<IO::Socket::Socks>, L<IO::Socket::SSL>,
L<Net::DNS::Native> and L<Plack> to provide advanced functionality if they are
installed.
modules such as L<EV>, L<IO::Socket::Socks>, L<IO::Socket::SSL>, and L<Plack>
to provide advanced functionality if they are installed.

=head2 Why reinvent wheels?

Expand Down

0 comments on commit 3f7dc3f

Please sign in to comment.