We just ran into this 'bug' as well. I assume the original poster has already moved on with his life, but for posterity, it's a simple difference of how IO::Async and perl handle file descriptors by default: perl choosing to keep them alive and IO::Async opting for more isolation and choosing to close all open filehandles that are not enumerated to keep.

What this means is that there is an additional setup argument in all (or at least all that I know of) IO::Async routines that cause forks that allows you to pass the actions for filehandles you don't want to close. If you have particular files that are the only ones you want to keep open, you can do something fancier, but if all you want is to make the errors go away and go on with your life, the code snippet is pretty simple. If you are going for this brute force approach you'll probably want to try and do this near the initial setup of your logger, or at least before you start creating channels, and try not to have any other files open. Otherwise you're liable to end up performing actions on IO::Async Channels that you probably don't want to mess with. Also, if your forked code ever calls exit, you'll want to follow the advice of perlfork from above and use _exit from posix instead (assuming you are on linux).

# Skip the builtins, they are all kept and it doesn't hurt to have # them but they are already handled. my @fds = grep { $_ > 2 } IO::Async::OS->potentially_open_fds(); # Keep them all open. Parens are to make the parser trust that # map was given a code reference and not a hash reference my @setup = map { ("fd$_" => 'keep', ) } @fds; # ... later ... my $thing = IO::Async::Whatever( code => sub { ... }, setup => \@setup );

In reply to Re: “Bad file descriptor” using Log4Perl and IO::Async by TimTom0123
in thread “Bad file descriptor” using Log4Perl and IO::Async by jgstratton

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.