RL has asked for the wisdom of the Perl Monks concerning the following question:

Hi and Happy Holidays to everbody!

I'ld be happy to get some input on a problem raising it's head once in a while though I know in theory it shouldn't be a problem at all.

The short question is:
Is there any known issue with Perls flock() implementation on CentOS 5.5 regarding exclusive locks?

The long version:
My webapplication utilizes exclusive locks whenever a file is read or written. I'm aware that in some environments this approach won't work as expected (e.g. BSDlike operating systems / network mounted file systems). For those cases the application can switch to a semaphore locking mechanism.
The approach seems to work fine for several years now on various servers.

However, during the past months I stumbled across 2 servers where once in a while exclusive locks are granted but never released. Only solution is to remove the lockfile (it's a separate lockfile while accessing a DBM database via DB_File).

I came across such a behaviour on Solaris with network mounted filesystem, so it's not absolutely new to me. Surprisingly these two servers are both CentOS 5.5 with Perl 5.8.8.
Searched the net and CentOS website but couldn't even find anybody raising the issue anywhere.

Regarding the application I'm not aware of any issue which could cause the scripts to hang and not release the lock. ... of course this doesn't mean there is no unknown bug.

Currently I'm a bit at a loss where to look. Maybe someone here has experienced a similar issue and is willing to share some thoughts and guide me into the right direction.

Thanks a lot
RL

Replies are listed 'Best First'.
Re: Exclusive locks on CentOS 5.5
by Khen1950fx (Canon) on Dec 29, 2010 at 10:19 UTC
    At least on the server-side, there's a conflict between flock()/BSD, which perl uses, and flock()/POSIX for which I really couldn't find a decent solution for but to workaround it by using LockFile::Simple. It's not based on flock() or lockf() and can be customized.

      Hi Khen1950fx.

      At a first glance LockFile::Simple seems to be much better than my home-brewed semaphore solution, which isn't much of a surprise to me :).

      I'll take a closer look and likely will use it soon.

      Thanks
      RL

Re: Exclusive locks on CentOS 5.5
by Anonymous Monk on Dec 29, 2010 at 09:19 UTC
    Is there any known issue with Perls flock() implementation on CentOS 5.5 regarding exclusive locks?

    linux comes with flock, and perl relies on the systems flock implementation.

    Solaris with network mounted filesystem

    I would check in network filesystem logs

      Thanks for the pointer.
      Sorry, my question wasn't accurate. I should have asked for issues with CentOS's system flock used by Perl instead of Perls flock implementation.

      RL

Re: Exclusive locks on CentOS 5.5
by zwon (Abbot) on Dec 29, 2010 at 11:27 UTC
    However, during the past months I stumbled across 2 servers where once in a while exclusive locks are granted but never released. Only solution is to remove the lockfile (it's a separate lockfile while accessing a DBM database via DB_File).

    I don't think your problem have anything to do with flock(2), as it does not create any lockfiles.