Skip to content

Commit

Permalink
Prevent exception caused by $service.stop
Browse files Browse the repository at this point in the history
Since `poll_one` is a blocking call, when service is stopped it throws
with `X::AdHoc` due to -1 returned by `zmq_poll`. Unfortunately,
`poll_one` doesn't use `zmq_die` and therefore there is no way to
determine if the error is caused by socket closing or not. For this
reason this PR relies on `$closer` value to find out if the exception
must be rethrows or dropped.

PR arnsholt/Net-ZMQ#22 is submitted to replace plain `die` with
`zmq_die`. But until then this PR should be ok get things straighten
out.
  • Loading branch information
vrurg committed Mar 6, 2021
1 parent fe298e5 commit 43469bb
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Cro/ZeroMQ/Internal.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ role Cro::ZeroMQ::Source::Impure does Cro::Source does Cro::ZeroMQ::Component::I
start {
loop {
last if $closer;
CATCH { default { .rethrow unless $closer } }
my $event = poll_one(self!socket, 100, :in);
if $event > 0 {
$messages.emit: Cro::ZeroMQ::Message.new(parts => self!socket.receivemore);
Expand Down Expand Up @@ -133,6 +134,7 @@ role Cro::ZeroMQ::Source::Pure does Cro::Source does Cro::ZeroMQ::Component::Pur
start {
loop {
last if $closer;
CATCH { default { .rethrow unless $closer } }
my $event = poll_one($isocket, 100, :in);
if $event > 0 {
$messages.emit: Cro::ZeroMQ::Message.new(parts => $isocket.receivemore);
Expand Down

0 comments on commit 43469bb

Please sign in to comment.