I can replicate the issue with 5.8.x, but not with 5.10.0. The exact limit seems to be 2048 (try something like for my $max (2035..2050) {...} to verify yourself).  A bit of digging in the 5.8.8 sources suggests this might have to do with a constant in perlio.c:

#define PERLIO_MAX_REFCOUNTABLE_FD 2048

which would make PerlIOUnix_dup() fail if fd >= PERLIO_MAX_REFCOUNTABLE_FD:

PerlIO * PerlIOUnix_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int fl +ags) { PerlIOUnix *os = PerlIOSelf(o, PerlIOUnix); int fd = os->fd; if (flags & PERLIO_DUP_FD) { fd = PerlLIO_dup(fd); } if (fd >= 0 && fd < PERLIO_MAX_REFCOUNTABLE_FD) { f = PerlIOBase_dup(aTHX_ f, o, param, flags); if (f) { /* If all went well overwrite fd in dup'ed lay with the du +p()'ed fd */ PerlIOUnix_setfd(aTHX_ f, fd, os->oflags); return f; } } return NULL; }

In Perl 5.10.0, the respective number of refcountable file descriptors is dynamically resized as needed...

(In case you really want to know, just modify the value, recompile perl, and try again to test the hypothesis :)


In reply to Re: perl bug? illegal seek with dup and many filehandles (PERLIO_MAX_REFCOUNTABLE_FD) by almut
in thread perl bug? illegal seek with dup and many filehandles by flipper

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.