Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-38853

QLockFile may fail to unlock() due to race condition

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.2.1
    • Fix Version/s: 5.4.0
    • Component/s: Core: I/O
    • Labels:
      None
    • Environment:
      Windows 7 x86, NTFS
    • Commits:
      7b9f7f3891230ddd2b2ef5cf3c760a605a02ee96

      Description

      The current implementation of QLockFile::unlock() contains a race condition with QLockFilePrivate::getLockInfo(). This leads to situations where the lock file is not deleted even though its owner hasn't crashed. Thus, only stale timeout can resolve the situation later.

      Steps to reproduce:
      1) Let's take example function void test()

      { QFile lock("c:/test.lock"); lock.lock(); }

      2) Open two Qt Creators with the project.
      3) In the first, set breakpoint on line "QFile::remove(d->fileName)" in QLockFile::unlock() and step to it.
      4) In the second, set breakpoint on line "QByteArray pidLine = reader.readLine();" in QLockFilePrivate::getLockInfo() and step to it.
      5) Let the first debugger run (QFile::remove() will fail. If I called ::DeleteFile(), the last error would be ERROR_SHARING_VIOLATION).
      6) Let the second debugger run (it will wait forever).

      Possible fix:
      Use two files, one empty .lock (for locking) and one .lock.info (containing the metadata).

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            dfaure David Faure (Private)
            Reporter:
            mys007 Martin Simonovsky
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes