croservices/cro-websocket

Client hides exceptions that occur further in the pipeline

Altai-man opened this issue · 6 comments

See https://stackoverflow.com/questions/51405074/crowebsocketclient-doesnt-work/51408569#51408569

I am not sure immediately where we can fix that, but this has to be fixed.

The reason is that web-socket routine-based transformation is not tied with outer supply chain.

Found this issue from a search on stackoverflow -- I'm trying to do something dead easy. Just connect to a websocket and print out whatever comes back.

use Cro::WebSocket::Client;

my $uri = 'ws://host:port/blah/blah';

my $conn = await Cro::WebSocket::Client.connect($uri);

react {
    whenever $conn.messages {
        await(.body).print
    }
}

If the server goes down, it just hangs forever.

This Mojo code says "closed" and exits immediately if the server goes down:

use Mojo::UserAgent;

my $uri = 'ws://host:port/blah/blah';

my $ua = Mojo::UserAgent->new;

$ua->websocket($uri => sub {
    my ($ua, $tx) = @_;
    $tx->on(message => sub {
                my ($tx, $msg) = @_;
                print $msg;
            });
    $tx->on(finish => sub {
                say "closed";
            });
});

Mojo::IOLoop->start;

Well, that's quite a serious design issue indeed, but it hasn't been decided yet how can we patch it without breaking backward compatibility. Perhaps @jnthn thought on some directions where we can move to?

There are at least two different issues here:
1)When exit-ed, Server does not kill its response objects. Thus as WebSocket is implemented as an infinite response to client's bytestream, web-socket blocks continue to go even when the server is dead already.
2)Clients indeed hides the exceptions... Which is a completely different issue.

Started an investigation...

I am splitting the issue... Client exception will be here, zombie server will be in another place.