Skip to content

Websocket not always keeping Close promise #27

@rbt

Description

@rbt

Websocket Close Promise doesn't fire during abnormal closures. A poorly configured firewall lead me to finding out that timed-out connections were not being cleaned up.

The below script simply sets up a socket and tells the user to run ss --kill in another session. This isn't exactly the same as the firewall timeout, but it does demonstrates the same issue.

I do get a "software caused connection abort" message which seems to originate from libuv. A connection timeout doesn't print a message in the terminal.

CRO_TRACE=1 indicates many components receive a DONE event.

use Cro::HTTP::Router;
use Cro::HTTP::Router::WebSocket;
use Cro::HTTP::Server;
use Cro::WebSocket::Client;

my $http-request;
my $application = route {
  get -> 'websocket' {
    $http-request = request;

    web-socket -> $incoming, $close {
      supply {
        whenever $incoming -> $msg {
           await($msg.body).say;
        }
        whenever $close {
           say "NEVER HERE";
        }
      }
    }
  }
}

my $cro-service = Cro::HTTP::Server.new(:http<1.1>, :host<0.0.0.0>, :port<10200>, :$application);
$cro-service.start;

{
    my $connection = await Cro::WebSocket::Client.connect: 'http://localhost:10200/websocket';
    $connection.send('Have Connection');
}

# Text will report "software caused connection abort" but $close will not fire.
say 'Run: sudo ss --kill dst %s/32 dport %s'.sprintf($http-request.connection.peer-host, $http-request.connection.peer-port);

react whenever signal(SIGINT) {
    $cro-service.stop;
    exit;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions