Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible deadlock with web socket #64

Open
Demayl opened this issue Apr 2, 2018 · 0 comments
Open

Possible deadlock with web socket #64

Demayl opened this issue Apr 2, 2018 · 0 comments

Comments

@Demayl
Copy link

Demayl commented Apr 2, 2018

When using the example code below:

  1. After a while it hangs ( for new connections too ) and memory usage goes crazy.
    2. In some cases it hangs only for a particular connection and after new connect it works.
    Edit: case 2 is ok in 0.7.4

Tried with some other web-socket servers and the html example works as expected.

This is Rakudo version 2018.03-147-g232c664 built on MoarVM version 2018.03-68-ged4201e
implementing Perl 6.c.

Perl 6 code

#!/usr/bin/env perl6
use v6.c;
my $chat = Supplier.new;
use Cro::HTTP::Router;
use Cro::HTTP::Router::WebSocket;
use Cro::HTTP::Server;

my $app = route {
        get -> 'chat' {
            web-socket -> $incoming {
                supply {
                    whenever $incoming -> $message {
                        $chat.emit("OK-"~(await $message.body-text));
                    }
                    whenever $chat -> $text {
                        emit $text;
                    }
                }
            }
        }
};

say "BEGIN";
my $service = Cro::HTTP::Server.new: :host('127.0.0.1'), :port(8888), :application($app);
say "Start";
$service.start;

say "Listen";

react whenever signal(SIGINT) { say "GOT KILL INT.....EXIT"; $service.stop; exit; }

HTML client

<!doctype html>
<html>
    <body>
    <div id="terminal"><textarea id="area"></textarea></div>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>

    <script type="text/javascript">
        var socket = new WebSocket('ws://127.0.0.1:8888/chat');
        socket.onopen = function(){ console.log("opened"); test() };
        socket.onclose = function(){ console.log("closed") };
        socket.onmessage = function(ev){ $("#area").html(ev.data); };
        socket.onerror = function(ev){ console.log("ERROR: " + ev.data) };

        $(window).on('beforeunload', function(){
            console.log("Close socket");
            socket.close();
        });
        function test(){
            setInterval(function(){ socket.send("PING");},10);
            setTimeout(function(){for(var i=0; i<2000; i++){ for(var x=0; x<10; x++){ socket.send(i+":"+x) } }},100);
            setTimeout(function(){for(var i=0; i<2000; i++){ for(var x=0; x<10; x++){ socket.send(i+":"+x) } }},100);
        }
    </script>
    </body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant