Skip to content

[BZ-4214] ACE_File_Lock constructed on already-locked file fails lock forever, even after it's freed #4214

@jwillemsen

Description

@jwillemsen
Field Value
Bugzilla ID 4214
Reporter @shuston
Assigned to DOC Center Support List (internal)
Product ACE
Component ACE Core
Version 6.3.0
Platform / OS x86 / Windows NT
Priority P3
Severity normal
Status NEW
Resolution
Created 2016-06-07 14:08:18 -0500

Originally posted by @shuston on 2016-06-07 14:08:18 -0500


From John Lilley:

On Windows, if a thread attempts to create an ACE_File_Lock while another thread already has the file write-locked, it results in an error. But the error is simply printed to the console:

ACE_File_Lock::ACE_File_Lock: Permission denied E:\DataManagement\RPDM\Server\unit_tests\SystemLockTest.lock

No exception is thrown, but from then on, the TryLock() method will always fail, even after the other thread has released the lock.

The problem is here:
ACE_File_Lock::ACE_File_Lock (ACE_HANDLE h,
bool unlink_in_destructor)
: removed_ (false),
unlink_in_destructor_ (unlink_in_destructor)
{
// ACE_TRACE ("ACE_File_Lock::ACE_File_Lock");
if (ACE_OS::flock_init (&this->lock_) == -1)
ACELIB_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("ACE_File_Lock::ACE_File_Lock")));
this->set_handle (h);
}

The handle gets set as ACE_INVALID_HANDLE. Fortunately, there is simple workaround. I create the ACE_File_Lock and call TryLock() all at once, and if TryLock fails I destruct the ACE_File_Lock until next attempt.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions