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

IO::Socket::Async server throws uncatchable exception in case of encoding errors #5542

Closed
p6rt opened this issue Aug 6, 2016 · 4 comments
Closed
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 6, 2016

Migrated from rt.perl.org#128862 (status was 'resolved')

Searchable as RT128862$

@p6rt
Copy link
Author

p6rt commented Aug 6, 2016

From @smls

Golfed program to demonstrate the problem​:

  my $server = IO​::Socket​::Async.listen('localhost', 3333);
  $server.tap​: -> $conn {
  $conn.Supply.tap​: -> $message { say $message.perl }
  }
 
  my $client = IO​::Socket​::Async.connect('localhost', 3333).then​: {
  .result.write(Blob.new​: 144);
  }
 
  await $client, $server;

It prints the following, and exits​:

  Unhandled exception​: Malformed UTF-8

In practice, having a server than can be crashed at will by any (even not-authenticated) client is of course LTA.
It seem the only way to prevent this, is to use .Supply(​:bin) to work with Buf's, which is needlessly cumbersome for text-based protocols.

I tried to catch the exception in the following ways, to prevent it from exiting the program, but none had an effect​:

1) CATCH or try/CATCH in a bunch of different places
2) Assigning to $*SCHEDULER.uncaught_handler
3) Specifying a :quit handler for both .tap's

@p6rt
Copy link
Author

p6rt commented Sep 8, 2016

From @jnthn

On Sat Aug 06 11​:25​:38 2016, smls75@​gmail.com wrote​:

Golfed program to demonstrate the problem​:

my $server = IO​::Socket​::Async.listen('localhost', 3333);
$server.tap​: -> $conn {
$conn.Supply.tap​: -> $message { say $message.perl }
}

my $client = IO​::Socket​::Async.connect('localhost', 3333).then​: {
.result.write(Blob.new​: 144);
}

await $client, $server;

It prints the following, and exits​:

Unhandled exception​: Malformed UTF-8

In practice, having a server than can be crashed at will by any (even
not-authenticated) client is of course LTA.
It seem the only way to prevent this, is to use .Supply(​:bin) to work
with Buf's, which is needlessly cumbersome for text-based protocols.

I tried to catch the exception in the following ways, to prevent it
from exiting the program, but none had an effect​:

1) CATCH or try/CATCH in a bunch of different places
2) Assigning to $*SCHEDULER.uncaught_handler
3) Specifying a :quit handler for both .tap's

Fixed, and test added in S32-io/IO-Socket-Async.t for this and a couple of other related cases. (Under the hood, the whole way we handle decoding strings with async sockets has been given a good overhaul.)

The typical way to handle such errors would be your option 3 (or, if using the supply/whenever syntax, a QUIT phaser). It should now also, as a last gasp, be passed to option 2.

/jnthn

@p6rt
Copy link
Author

p6rt commented Sep 8, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Sep 8, 2016

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Sep 8, 2016
@p6rt p6rt added the conc label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant