It seems I am loosing my file descriptors when using IO::Async::Function in fork mode. This doesn't seem to happen when using this in thread mode(which I cannot use for this...). The only ways around this I can think of is resetting my logger and init'ing my logger multiple times, which I assume is wrong.

Here is basically what the code is doing:

use IO::Async::Loop; use IO::Async::Function; use strict; use warnings; use Log::Log4perl; unless ( Log::Log4perl->initialized() ) { Log::Log4perl::init("~/blah.cfg"); } my $logger = Log::Log4perl->get_logger('main.log1'); $logger->info( "$$: Starting" ); my $loop = IO::Async::Loop->new; my $function = IO::Async::Function->new( code => sub { my ( $in_num ) = @_; my $logThing = LogThing->new(); $logThing->do_it( $in_num ); return( $in_num + 1 ); }, ); $loop->add( $function ); my @futures; foreach my $num ( 2..3 ) { push @futures, $function->call( args => [ $num ] ); } $loop->await_all( @futures ); $function->stop; $logger->info( "$$: Exiting" ); 0; package LogThing; use Moose; use strict; use warnings; use Log::Log4perl; use Try::Tiny; sub do_it { my ( $self, $in_num ) = @_; my $logger = Log::Log4perl->get_logger('main.trans'); print "Sleeping $in_num\n"; sleep( $in_num ); try { $logger->info("$$: Done $in_num"); } catch { warn "Some weird log4perl object conflict $_"; }; } 0;

When executing, I get an "Bad file descriptor" error:

Sleeping 2
Sleeping 3
Some weird log4perl object conflict Cannot write to '/var/log/blah/trans.log': Bad file descriptor at /usr/lib/perl5/site_perl/5.18.2/Log/Log4perl/Appender/File.pm line 267.
Some weird log4perl object conflict Cannot write to '/var/log/blah/trans.log': Bad file descriptor at /usr/lib/perl5/site_perl/5.18.2/Log/Log4perl/Appender/File.pm line 267.


In reply to “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.