Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
There's more than one way to do things
 
PerlMonks  

Spurious "Invalid Argument" on file open

by rovf (Priest)
on Oct 23, 2012 at 09:01 UTC ( #1000458=perlquestion: print w/ replies, xml ) Need Help??
rovf has asked for the wisdom of the Perl Monks concerning the following question:

Part of our application, which runs in a mixed Windows / Linux / Solaris environment, is a small Perl program, which ats ome point executes
if(-e $rule_file) { if(open(my $rule_fh,'<',$rule_file)) { .... } else { die "Can not read file $rule_file : $!"; } }
The variable $rule_file contains one of two values, depending on whether the script runs on Linux/Solaris, or Windows, but in both cases, it points (absolute path) to the same file. On Linux and Solaris, the file is mounted via NFS. On Windows, the file is accessed via CIFS, and $rule_file is an UNC path.

This small program is executed frequently. It might well be that at a certain point in time, a dozen processes on various Linux-, Solaris- and Windows processes execute the script and try to open the file. Since the file is only opened for reading, I believe that this should not be a problem.

From our logs, I see however that the open occasionally fails with

Can not read file ....... : Invalid argument

This happens rarely (maybe in 1 out of 1000-2000 executions), and if it happens, it always fails on Windows, never on Linux or Solaris. It looks very much like a concurrency issue, but the wording of the error message, "invalid argument", surprises me.

Any idea what could be the reason? Maybe some Windows or CIFS quirk, when many processes try to open a file at the same time?

-- 
Ronald Fischer <ynnor@mm.st>

Comment on Spurious "Invalid Argument" on file open
Select or Download Code
Re: Spurious "Invalid Argument" on file open
by Anonymous Monk on Oct 23, 2012 at 09:14 UTC
    check the event log
    $ perl -le " $!= $^E = 22; printf qq/%d %s\n%d %s\n/, $!,$!,$^E,$^E " 22 Invalid argument 22 The device does not recognize the command
      I asked our sysadmins to check the event log, but nothing to be found :-(


      Any other idea?

      -- 
      Ronald Fischer <ynnor@mm.st>
Re: Spurious "Invalid Argument" on file open
by BrowserUk (Pope) on Oct 23, 2012 at 12:28 UTC

    What do you get from $^E?:

    if(-e $rule_file) { if(open(my $rule_fh,'<',$rule_file)) { .... } else { die "Can not read file $rule_file : $! / $^E"; } }

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

      What do you get from $^E
      I don't know (yet). I already thought to output this value too, but I can't do any changes to the application during the next couple of weeks, so this has to wait.

      I thought maybe the effect I'm experiencing might be well known already, so someone could already have a good guess what's going wrong. I now understand that this error code is far too general, to reasonably diagnose the problem....

      -- 
      Ronald Fischer <ynnor@mm.st>

        The most likely reason -- especially given the network involvement -- is TOCTTOU.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        RIP Neil Armstrong

Re: Spurious "Invalid Argument" on file open
by AnomalousMonk (Monsignor) on Oct 23, 2012 at 14:52 UTC

    Hi rovf.
    This question arises solely from idle curiosity and has no bearing on your problem. I was wondering why you use the
        if (open ...) { process... } else { die "error: $!" }
    file open and process construct given in your OP rather than the less verbose and, IMHO, cleaner  open ... die "..."; idiomatic construct?

    I notice something similar in bioinformatics applications, where something like
        unless (open ...) {
            print STDERR "error message: $!";
            exit;
            }
    is often seen. I could understand if the exit built-in was used to return a distinctive error code to the OS, but I only seem to see  exit; (returning no error code) or  exit(1); used. Anyone have any notions on the rationale of this idiom?

    Again, just idle curiosity here.

      (I was under the mistaken impression that without a number given, exit returns with exit code of previous command. After reading the exit pod,) exit will return with 0 in case of second example.

      I would say unfamiliarity of the shorter version might be the reason for the verbose code. Also, exit cannot simply be caught in eval {}; unlike die or croak but I doubt that that would be the reason for cited uses of exit.

      The code posted here, was a condensed version, to focus on the problem in question. In my realy code, the else branch contains other cleanup code, which is, however, not relevant to our problem.


      -- 
      Ronald Fischer <ynnor@mm.st>

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1000458]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-04-19 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (480 votes), past polls