Hi, I have a large script which, among other things, gets output from several external workers. A problem occurs when workers complete at nearly the same time. At least, I think that is the reason. Then, randomly, instead of data, application may receive an empty string.

Here's a watered down version of server:

use strict; use warnings; use feature qw/ say /; use utf8; use Sereal qw/ sereal_decode_with_object /; use IO::Async::Loop; use IO::Async::Listener; use Future; $, = "\t"; my $PORT = 53123; my $num = 0; my $dec = Sereal::Decoder-> new; my $loop = IO::Async::Loop-> new; my $lst = IO::Async::Listener-> new( on_stream => sub { my ( $self, $stream ) = @_; $stream-> configure( on_read => sub { 0 }); $loop-> add( $stream ); $stream-> read_until_eof-> on_ready( sub { my $F = shift; my ( $buf, $eof ) = $F-> get; print ++$num, length( $buf ), unpack( 'H*', $buf ), ''; say sereal_decode_with_object( $dec, $buf ) }) } ); $loop -> add( $lst ); $lst-> listen( addr => { family => 'inet', socktype => 'stream', ip => '127.0.0.1', port => $PORT, }, )->on_done( sub { say "Listening on $PORT..." }); $loop-> run;

And here is a simple worker:

use strict; use warnings; use feature qw/ say /; use utf8; use autodie; use Sereal qw/ encode_sereal /; use IO::Socket::INET; my $PORT = 53123; say "hi, i'm $$"; while () { my $sock = new IO::Socket::INET( PeerHost => '127.0.0.1', PeerPort => $PORT, Proto => 'tcp', ) or die; binmode $sock; print $sock encode_sereal $$; $sock-> close; select( undef, undef, undef, 0.01 ); }

Then I run server and a single worker. After random interval, server crashes:

... 1685 9 3df3726c030020e009 1248 1686 9 3df3726c030020e009 1248 1687 9 3df3726c030020e009 1248 1688 9 3df3726c030020e009 1248 Sereal: Error: Bad Sereal header: Not a valid Sereal document. at offs +et 1 of input at srl_decoder.c line 573 at server.pl line 29. 1689 0

Why does it happen and can anything be done about it?


In reply to Problem with IO::Async application by vr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.