I have error when trying to do two concurrent requests which upgrades to tls.
#!/usr/bin/perl
use Mojo::Base -strict;
use Mojo::IOLoop;
use Mojo::IOLoop::TLS;
use Mojo::IOLoop::Client;
use Mojo::IOLoop::Server;
#$IO::Socket::SSL::DEBUG = 3;
my $server = Mojo::IOLoop::Server->new;
my $client = Mojo::IOLoop::Client->new;
my ($server_handle, $client_handle);
my ($client_stream, $server_stream);
sub upgrade_handle {
my ($handle, $is_server, $cb) = @_;
my $tls = Mojo::IOLoop::TLS->new($handle);
$tls->on(upgrade => sub { $cb->(pop) });
$tls->on(error => sub { warn pop });
$tls->negotiate(server => $is_server);
}
sub upgrade_handles {
Mojo::IOLoop->delay(
sub {
my $d = shift;
upgrade_handle($server_handle, 1, $d->begin(0));
upgrade_handle($client_handle, 0, $d->begin(0));
}, sub {
my ($d, $server_handle, $client_handle) = @_;
say 'YEAH';
Mojo::IOLoop->singleton->reactor->io($server_handle => sub {})->watch($server_handle, 1, 0);
Mojo::IOLoop->singleton->reactor->io($client_handle => sub {})->watch($client_handle, 1, 0);
}
);
}
$client->on(connect => sub {
$client_handle = pop;
#upgrade_handles();
Mojo::IOLoop->timer(0.1 => sub { upgrade_handles() });
});
$client->on(error => sub { warn pop });
$server->on(accept => sub {
$server_handle = pop;
$client->connect(address => 'www.yandex.ru', port => 443);
});
$server->listen(port => 8443);
$server->start;
Mojo::IOLoop->start;
I have error when trying to do two concurrent requests which upgrades to tls.
I have this errors when run this script
Client send message with that request
I try to discuss this problem in mojo irc channel, but nobody understand me.
When i enable debug mode for IO::Socket::SSL, i see output like that:
So, after accept ssl handshake IO::Socket::SSL begin accept it again.
If comment client upgrade or server upgrade then all will work perfectly. So, problem occure when exists two concurrent requests.
I don't konw what to do...