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):
-Dansub 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; } }
|
|---|
| 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 |