flock incorrectly detects deadlock on 7-stable and current



Hi,

We have been trying to track down a problem with one of our apps which
does a lot of flock(2) calls. flock returns errno 11 (Resource
deadlock avoided) under certain scenarios. Our app works fine on
7-Release, but fails on 7-stable and -current.

The problem appears to be when we have at least three processes doing
flock() on a file, and one is trying to upgrade a shared lock to an
exclusive lock but fails with a deadlock avoided.

Attached is a simple flock() test program.

a. Process 1 requests and gets a shared lock
b. Process 2 requests and blocks for an exclusive lock
c. Process 3 requests and gets a shared lock
d. Process 3 requests an upgrade to an exclusive lock but fails (errno
11)

If we change 'd' to
Process 3 requests unlock, then requests exclusive lock, it works.


The manual page says:

"A shared lock may be upgraded to an exclusive lock, and vice versa,
simply by specifying the appropriate lock type; this results in the
previous lock being released and the new lock applied (possibly after
other processes have gained and released the lock)."

The manual page doesn't mention that flock() can fail with a deadlock.


Our test environment is:
- 8 core Intel machine running i386 stable
- 4 core Intel machine running amd64 current (20080508)
- 4 core Intel machine running amd64 stable (20080508)
- 2 core AMD machine running i386 stable (20080418)
- 2 core AMD machine running i386 stable (20080418)
- single core (no hyperthreading) i386 stable (20080418)

There appears to have been changes to kern_lockf.c and other stuff
around the 10th April to do with deadlock detection. We don't see the
problem on 6.2-stable, 7-Release, or 7-stable pre ~10th April.

Paul.
_______________________________________________
freebsd-stable@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscribe@xxxxxxxxxxx"

Relevant Pages

  • ASP requests and locking
    ... I'm currently writing a web app that is designed to handle a very heavy traffic load - about 3 million requests per day, ... So if I'm locking to get at the value of a hashtable in the ASP cache, I'm locking all other requests for this particular app pool until the lock block exits. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: ASP requests and locking
    ... traffic load - about 3 million requests per day, ... When using the lock(x) C# idiom, ... locking to get at the value of a hashtable in the ASP cache, ... A final question about locking and the ASP cache. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: file locking
    ... > user2 on a unix machine SunOS 5.9 ... Nowhere here do you give up your lock. ... > adding things to the queue file are implemented with exclusive locking ... > time 0 user1 requests LOCK_SH ...
    (comp.lang.perl.misc)
  • Re: [PATCH 1a/7] dlm: core locking
    ... > - The queue of ungranted conversion requests for the resoure is empty. ... > - The queue of ungranted new requests for the resource is empty. ... If you've got a read lock, ... That is always needed if you've got a lock directory model --- you have ...
    (Linux-Kernel)
  • Re: Creating a Shared Lock
    ... A second thread that is called once every second ... needs to lock so the other function does not get called while its running. ... In SQL you would do this by creating a shared lock on the first function ... shared access but once a thread has an exclusive lock any shared locks will ...
    (microsoft.public.dotnet.languages.csharp)