mojolicious / mojo

:sparkles: Mojolicious - Perl real-time web framework
https://mojolicious.org
Artistic License 2.0
2.66k stars 577 forks source link

websocket problem? #1078

Closed fayland closed 7 years ago

fayland commented 7 years ago

Steps to reproduce the behavior

https://gist.github.com/fayland/67e72492ab9d13f46a7f4d48b5d6891f

run the two scripts. anyevent-websocket.pl can return us

M: $VAR1 = \bless( { 'opcode' => 1, 'body' => '4100720dfbc176dfb493-0000000500005d97' }, 'AnyEvent::WebSocket::Message' );

while mojo returns nothing.

Expected behavior

at least some body comes back

Actual behavior

nothing is there.

jhthorsen commented 7 years ago

I don't know what's going on, but maybe someone else can understand what is going over the wire?

-- Non-blocking request (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)
-- Connect 9ec950285de19d0e87d50234c28582bc (https://realtime-bir.paddypower.com:443)
-- Client >>> Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)
GET /diffusion?v=4&ty=WB HTTP/1.1\x0d
Accept-Encoding: gzip\x0d
Host: realtime-bir.paddypower.com\x0d
User-Agent: Mojolicious (Perl)\x0d
Sec-WebSocket-Version: 13\x0d
Sec-WebSocket-Key: NjkwMjU2NDg3OTAxNDUwNg==\x0d
Upgrade: websocket\x0d
Sec-WebSocket-Extensions: permessage-deflate\x0d
Content-Length: 0\x0d
Connection: Upgrade\x0d
\x0d

-- Client >>> Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)

-- Client <<< Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)
HTTP/1.1 101 Switching Protocols\x0d
Upgrade: WebSocket\x0d
Connection: Upgrade\x0d
Sec-WebSocket-Accept:2tFBwo9w5oXPJjYZh13e/EzUQmA=\x0d
Set-Cookie: session=2aaf24da0eae4498-0000000100000a7e; HttpOnly\x0d
\x0d

-- Client >>> Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)

Wonder if AnyEvent::WebSocket::Client has support for something similar to MOJO_USERAGENT_DEBUG=1...

guest20 commented 7 years ago

If it were anything, it would be AE_VERBOSE=9, but is no logging in AnyEvent::HTTP that I can see.

fskale commented 7 years ago

Hello Fayland, in your testscripts you forgot the "use v5.10" term for the say function. Imho it's no mojolicious problem since the site responsiveness is very slow even using the http proto. Anyhow, i got something back usingMojo::UserAgent:

-- Non-blocking request (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)
-- Connect bb2df23965d20425be23567937deb783 (https://realtime-bir.paddypower.com:443)
-- Client >>> Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)
GET /diffusion?v=4&ty=WB HTTP/1.1\x0d
Host: realtime-bir.paddypower.com\x0d
Connection: Upgrade\x0d
Accept-Encoding: gzip\x0d
Sec-WebSocket-Extensions: permessage-deflate\x0d
Sec-WebSocket-Key: NTY3NjM4NjQxNzc5NDM5MA==\x0d
Content-Length: 0\x0d
Upgrade: websocket\x0d
Sec-WebSocket-Version: 13\x0d
User-Agent: Mojolicious (Perl)\x0d
\x0d

-- Client >>> Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)

-- Client <<< Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)
HTTP/1.1 101 Switching Protocols\x0d
Upgrade: WebSocket\x0d
Connection: Upgrade\x0d
Sec-WebSocket-Accept:XoAJp/6ocJi6y7BYbiC3bqE+Y0s=\x0d
Set-Cookie: session=4cfef4948e887d43-00000000000048c2; HttpOnly\x0d
\x0d
\x81'4\x02100\x024cfef4948e887d43-00000000000048c2
GOT 41004cfef4948e887d43-00000000000048c2
-- Client >>> Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)

I think of something like mod_request as the root cause.

Rgds. Franz

fayland commented 7 years ago

aha, I don't follow. each time I run the anyevent.pl I got result, but none for mojo one. I tested it once again. same result. did you get response each time you run the script? same script (just added use v5.10;)? thanks

fskale commented 7 years ago

Yes, even when disabling permessage-deflate Sec-WebSocket-Extension it get one message back. But: there are load balanced services behind it, take a look at the SSL Certs (i enabled SSL Debug Defaults). So, when talking to the host which answers with the thawte cert, i don't get back a message. So it's clear to be, that this is a backend problem. (Could be anything :-))

Working with QuoVadis Cert:

-- Non-blocking request (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)
-- Connect 8575e0fc23fa1443dc22ba0b78f6d0b8 (https://realtime-bir.paddypower.com:443)
Authority: /C=BM/O=QuoVadis Limited/CN=QuoVadis Root CA 2/C=BM/O=QuoVadis Limited/CN=QuoVadis Root CA 2
Authority: /C=BM/O=QuoVadis Limited/CN=QuoVadis Root CA 2/C=US/O=HydrantID (Avalanche Cloud Corporation)/CN=HydrantID SSL ICA G2
Authority: /C=US/O=HydrantID (Avalanche Cloud Corporation)/CN=HydrantID SSL ICA G2/C=IE/ST=Leinster/L=Dublin/O=Paddy Power Betfair Public Limited Company/OU=IT/CN=realtime.paddypower.com
-- Client >>> Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)
GET /diffusion?v=4&ty=WB HTTP/1.1\x0d
Sec-WebSocket-Key: NTA0NTU5MzAzNDkxNTA0NA==\x0d
Content-Length: 0\x0d
Connection: Upgrade\x0d
Accept-Encoding: gzip\x0d
Sec-WebSocket-Version: 13\x0d
Host: realtime-bir.paddypower.com\x0d
Upgrade: websocket\x0d
User-Agent: Mojolicious (Perl)\x0d
\x0d

-- Client >>> Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)

-- Client <<< Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)
HTTP/1.1 101 Switching Protocols\x0d
Upgrade: WebSocket\x0d
Connection: Upgrade\x0d
Sec-WebSocket-Accept:rl0ptGPvDHfiBXehsvDEp/dveB4=\x0d
Set-Cookie: session=bbeba4f96864ea84-00000004000048dd; HttpOnly\x0d
\x0d
\x81'4\x02100\x02bbeba4f96864ea84-00000004000048dd
GOT 4100bbeba4f96864ea84-00000004000048dd
-- Client >>> Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)

-- Client <<< Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)
\x81\x0f\x191491217700292\x01
GOT 1491217700292
-- Client >>> Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)

Not working (Thawte cert):


-- Non-blocking request (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)
-- Connect 8c2e1554f5e22be02e89a2b3f906acbb (https://realtime-bir.paddypower.com:443)
Authority: /C=US/O=thawte, Inc./OU=Certification Services Division/OU=(c) 2006 thawte, Inc. - For authorized use only/CN=thawte Primary Root CA/C=US/O=thawte, Inc./OU=Certification Services Division/OU=(c) 2006 thawte, Inc. - For authorized use only/CN=thawte Primary Root CA
Authority: /C=US/O=thawte, Inc./OU=Certification Services Division/OU=(c) 2006 thawte, Inc. - For authorized use only/CN=thawte Primary Root CA/C=US/O=thawte, Inc./CN=thawte SSL CA - G2
Authority: /C=US/O=thawte, Inc./CN=thawte SSL CA - G2/C=IE/ST=Dublin/L=Dublin/O=Power Leisure Bookmakers Limited/OU=IT/CN=*.paddypower.com
-- Client >>> Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)
GET /diffusion?v=4&ty=WB HTTP/1.1\x0d
Sec-WebSocket-Version: 13\x0d
Accept-Encoding: gzip\x0d
Connection: Upgrade\x0d
Host: realtime-bir.paddypower.com\x0d
Upgrade: websocket\x0d
Content-Length: 0\x0d
Sec-WebSocket-Key: NDUxMjM5OTg0MTA3MzMxOA==\x0d
User-Agent: Mojolicious (Perl)\x0d
\x0d

-- Client >>> Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)

-- Client <<< Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)
HTTP/1.1 101 Switching Protocols\x0d
Upgrade: WebSocket\x0d
Connection: Upgrade\x0d
Sec-WebSocket-Accept:jwtPHvefjjSAV/WNdD4tzLsBrng=\x0d
Set-Cookie: session=eb04aa7b99d7bbfb-000000000000d492; HttpOnly\x0d
\x0d

-- Client >>> Server (https://realtime-bir.paddypower.com/diffusion?v=4&ty=WB)

I think issuing a support ticket is the way to go ;-)

Sorry, forgot to post my testscript:

#!/usr/bin/env perl
use warnings;
use strict;
use v5.10;
use IO::Socket::SSL;
use Mojo::UserAgent;

IO::Socket::SSL::set_defaults(
        SSL_verify_mode => SSL_VERIFY_NONE,
    SSL_verify_callback => sub {
            say "Authority: $_[2]";
        return $_[0];
        }
);

my $ua = Mojo::UserAgent->new;
$ua = $ua->connect_timeout(60);

$ua->websocket('wss://realtime-bir.paddypower.com/diffusion?v=4&ty=WB' => sub {
   my ($ua, $tx) = @_;
   say 'WebSocket handshake failed!' and return unless $tx->is_websocket;
   $tx->on(message => sub {
      my ($tx, $msg) = @_;
      print "GOT $msg\n";
   });
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

Rgds. Franz

fayland commented 7 years ago

interesting. it really works now. thanks