Skip to content

Commit

Permalink
revert the addition of stream classes (added in 7.83), which have unf…
Browse files Browse the repository at this point in the history
…ortunately resulted in many Mojolicious applications becoming unstable
  • Loading branch information
kraih committed Aug 9, 2018
1 parent 44abadd commit 61f6cbf
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 1,036 deletions.
6 changes: 5 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

7.92 2018-08-10
7.92 2018-08-09
- This release reverts the addition of stream classes (added in 7.83), which
have unfortunately resulted in many Mojolicious applications becoming
unstable. While there are no known exploits yet, we've chosen to err on the
side of cautiousness and will classify this as a security issue.

7.91 2018-08-09
- Fixed a bug in Mojo::IOLoop::Stream where is_readable could not be called
Expand Down
49 changes: 6 additions & 43 deletions lib/Mojo/IOLoop.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,22 @@ sub acceptor {

sub client {
my ($self, $cb) = (_instance(shift), pop);
my $args = ref $_[0] ? $_[0] : {@_};

my $id = $self->_id;
my $client = $self->{out}{$id}{client} = Mojo::IOLoop::Client->new;
weaken $client->reactor($self->reactor)->{reactor};
my $class = delete $args->{stream_class} || 'Mojo::IOLoop::Stream';

weaken $self;
$client->on(
connect => sub {
delete $self->{out}{$id}{client};
my $stream = $class->new(pop);
my $stream = Mojo::IOLoop::Stream->new(pop);
$self->_stream($stream => $id);
$self->$cb(undef, $stream);
}
);
$client->on(error => sub { $self->_remove($id); $self->$cb(pop, undef) });
$client->connect($args);
$client->connect(@_);

return $id;
}
Expand Down Expand Up @@ -107,14 +105,12 @@ sub reset {

sub server {
my ($self, $cb) = (_instance(shift), pop);
my $args = ref $_[0] ? $_[0] : {@_};

my $server = Mojo::IOLoop::Server->new;
my $class = delete $args->{stream_class} || 'Mojo::IOLoop::Stream';
weaken $self;
$server->on(
accept => sub {
my $stream = $class->new(pop);
my $stream = Mojo::IOLoop::Stream->new(pop);
$self->$cb($stream, $self->_stream($stream, $self->_id, 1));

# Enforce connection limit (randomize to improve load balancing)
Expand All @@ -127,7 +123,7 @@ sub server {
$self->_not_accepting if $self->_limit;
}
);
$server->listen($args);
$server->listen(@_);

return $self->acceptor($server);
}
Expand Down Expand Up @@ -162,17 +158,6 @@ sub subprocess {

sub timer { shift->_timer(timer => @_) }

sub transition {
my ($self, $id, $class) = (_instance(shift), @_);

my $old = $self->stream($id);
my $new = $class->new($old->steal_handle);
$self->_stream($new, $id, !!$self->{in}{$id});
$old->transition($new);

return $new;
}

sub _id {
my $self = shift;
my $id;
Expand Down Expand Up @@ -407,14 +392,7 @@ Get L<Mojo::IOLoop::Server> object for id or turn object into an acceptor.
Open a TCP/IP or UNIX domain socket connection with L<Mojo::IOLoop::Client> and
create a stream object (usually L<Mojo::IOLoop::Stream>), takes the same
arguments as L<Mojo::IOLoop::Client/"connect"> in addition to C<stream_class>.
# Connect to 127.0.0.1 on port 3000 with a custom stream class
my $class = 'Mojo::IOLoop::Stream::HTTPClient';
Mojo::IOLoop->client({port => 3000, stream_class => $class} => sub {
my ($loop, $err, $stream) = @_;
...
});
arguments as L<Mojo::IOLoop::Client/"connect">.
=head2 delay
Expand Down Expand Up @@ -548,14 +526,7 @@ Remove everything and stop the event loop.
Accept TCP/IP and UNIX domain socket connections with L<Mojo::IOLoop::Server>
and create stream objects (usually L<Mojo::IOLoop::Stream>, takes the same
arguments as L<Mojo::IOLoop::Server/"listen"> in addition to C<stream_class>.
# Listen on port 3000 with a custom stream class
my $class = 'Mojo::IOLoop::Stream::HTTPServer';
Mojo::IOLoop->server({port => 3000, stream_class => $class} => sub {
my ($loop, $stream, $id) = @_;
...
});
arguments as L<Mojo::IOLoop::Server/"listen">.
# Listen on random port
my $id = Mojo::IOLoop->server({address => '127.0.0.1'} => sub {
Expand Down Expand Up @@ -663,14 +634,6 @@ seconds.
...
});
=head2 transition
my $stream =
Mojo::IOLoop->transition($id => 'Mojo::IOLoop::Stream::HTTPClient');
my $stream = $loop->transition($id => 'Mojo::IOLoop::Stream::HTTPClient');
Transition stream to a different class.
=head1 DEBUGGING
You can set the C<MOJO_IOLOOP_DEBUG> environment variable to get some advanced
Expand Down
22 changes: 0 additions & 22 deletions lib/Mojo/IOLoop/Stream.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ sub timeout {
return $self;
}

sub transition {
my ($self, $new) = @_;
@{$new}{qw(read written)} = @{$self}{qw(read written)};
$self->emit(transition => $new);
}

sub write {
my ($self, $chunk, $cb) = @_;

Expand Down Expand Up @@ -222,15 +216,6 @@ Emitted if new data arrives on the stream.
Emitted if the stream has been inactive for too long and will get closed
automatically.
=head2 transition
$stream->on(transition => sub {
my ($stream, $new_stream) = @_;
...
});
Emitted if the stream has transitioned to a different class.
=head2 write
$stream->on(write => sub {
Expand Down Expand Up @@ -336,13 +321,6 @@ Maximum amount of time in seconds stream can be inactive before getting closed
automatically, defaults to C<15>. Setting the value to C<0> will allow this
stream to be inactive indefinitely.
=head2 transition
$stream->transition($new_stream);
Transition stream to a different class. Note that this method is EXPERIMENTAL
and might change without warning!
=head2 write
$stream = $stream->write($bytes);
Expand Down
204 changes: 0 additions & 204 deletions lib/Mojo/IOLoop/Stream/HTTPClient.pm

This file was deleted.

Loading

0 comments on commit 61f6cbf

Please sign in to comment.