[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2772
  • Last Modified:

flock error - no locks available.

Here is a simple test script that creates the error.

use Fcntl qw(:DEFAULT :flock);
my $file = "test.txt";
print "Content-type:text/html\n\n";
local *FILE;
sysopen(FILE, $file, O_WRONLY | O_TRUNC | O_CREAT) or print "<p>Can't open $file: $!</p>";
flock(FILE, LOCK_EX) or print "<p>Can't flock LOCK_EX $file: $!</p>";
print FILE "Test\n";
flock(FILE, LOCK_UN) or print "<p>Can't flock LOCK_UN $file: $!</p>";
close(FILE);
print "<p>Done</p>";


It always produces the error:

Can't flock LOCK_EX test.txt: No locks available


I've never seen this before.  Anyone know why and how to fix it?
0
tsniff
Asked:
tsniff
1 Solution
 
TintinCommented:
I have seen various reports of the same problem which are related to Linux kernel bugs and NFS.

0
 
prakashagrCommented:

use Fcntl qw(:DEFAULT :flock);
my $file = "test.txt";
print "Content-type:text/html\n\n";
local *FILE;
sysopen(FILE, $file, O_WRONLY | O_TRUNC | O_CREAT) or print "<p>Can't open $file
: $!</p>";
flock(FILE, LOCK_EX) or print "<p>Can't flock LOCK_EX $file: $!</p>";
print FILE "Test\n";
flock(FILE, LOCK_UN) or print "<p>Can't flock LOCK_UN $file: $!</p>";
close(FILE);
print "<p>Done</p>";

~
[prakasha@linuxcvs prakasha]$ perl flock.pl
Content-type:text/html

<p>Done</p>[prakasha@linuxcvs prakasha]$


i am not getting that message, file is proper for me.

Prakash
0
 
tsniffAuthor Commented:
I know the file is fine.  It works on every server I have tested it on except one.  I am trying to find a reason and solution for that one.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
TintinCommented:
My best guess is that the file lives on a NFS directory.
0
 
tsniffAuthor Commented:
I believe it does....  if so, is there a way to flock over nfs?
0
 
TintinCommented:
As previously mentioned, I have seen reports of Linux kernel bugs preventing flock over NFS, so in order to fix this, your server would probably need a kernel upgrade.

As a workaround, you could use another file locking method.
0
 
ozoCommented:
Why not use a local file for a lock file?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now