Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Can flock occasionally fail on systems that support file locking?

by danb (Friar)
on Jul 10, 2003 at 17:01 UTC ( [id://273046]=note: print w/replies, xml ) Need Help??


in reply to Can flock occasionally fail on systems that support file locking?

Our experience is that 5.8.0 has had some changes with regard to locking. In 5.6, you were always gauranteed an flock, unless there was some monumental fatal error -- it just took a long time sometimes.

In 5.8, the new functionality seems to be that if it can't get the lock in a reasonable time-frame, it throws EINTR, and then wants you to try again later.

For the Interchange project, here is what they did (it seems to solve the problem for us):

sub flock_lock { my ($fh, $excl, $wait) = @_; my $flag = $excl ? $flock_LOCK_EX : $flock_LOCK_SH; if ($wait) { my $trylimit = $Vend::Cfg->{Limit}{file_lock_retries} || 5; my $failedcount; while ( ! flock($fh, $flag) and $failedcount < $trylimit ) { $failedcount++; select(undef,undef,undef,0.05 * $failedcount); } die "Could not lock file after $trylimit tries: $!\n" if ($fai +ledcount == $trylimit); return 1; } else { if (! flock($fh, $flag | $flock_LOCK_NB)) { if ($!{EAGAIN} or $!{EWOULDBLOCK}) { return 0; } else { die "Could not lock file: $!\n"; } } return 1; } }
-Dan
  • Comment on Re: Can flock occasionally fail on systems that support file locking?
  • Download Code

Replies are listed 'Best First'.
Re: Re: Can flock occasionally fail on systems that support file locking?
by rzward (Monk) on Jul 10, 2003 at 17:31 UTC
    Thank you for this information.

    According to the ISP's FAQ, the version of Perl on the Web server is 5.00503-2.

    However, this script is used on many web sites so I now have more motivation to put in error handling around the flock calls to handle the case where 5.8 is installed and flock times out.

    Thank you!

    Richard

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://273046]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-20 06:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found