Uploaded image for project: 'Artifactory Binary Repository'
  1. Artifactory Binary Repository
  2. RTFACT-20028

Copy of layers when pulling the same tag concurrently causes a deadlock

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 6.10.0, 6.11.0, 6.12.0
    • Fix Version/s: 6.13.0, 6.12.2, 6.10.8
    • Component/s: Docker
    • Labels:
      None
    • Regression:
      Yes

      Description

      RTFACT-17638 introduces a mechanism that copies image layers from tag X -> Y eagerly when the manifest.json is pulled. The following deadlock is a combination of an app-level lock and a DB lock.

      Pulling a docker manifest concurrently (3+) creates the following deadlock:

      1. Thread #1 - the fastest thread of the 3, moves layer X of the image to its new path, and commits the transaction.
      2. Thread #2  - the thread decides that layer X needs to be copied too (there is no lock that protects the docker business level from copying the same layer twice - nor does it check whether the target path exists or not). This thread then proceeds to overwriting the already existing layer at the target path. When overwriting Artifactory does the following:
        1. It removes the target file & saves the session (the lock on the path is released, before the TX is committed!)
        2. The target path is then re-created (another repoPath lock is required)
      3. Thread #3 - Initially waits to acquire a lock on the target path. When Thread #2 releases the lock @ #2.1, this thread "steals" the lock on the repoPath. So now, Thread #2 cannot re-acquire the lock (as required by #2.2), however, Thread #2 already holds a read-lock on the row in the database
      4. Thread #2 wants to proceed with re-creating the overwritten path, but the lock on the path was stolen by Thread #3. 
      5. The situation is a deadlock since Thread #2 waits for the app-level lock that Thread #3 holds, and Thread #3 waits for the DB lock that Thread #2 holds. 

      (See http-nio-8081-exec-3 and http-nio-8081-exec-2 on the attached thread dump)

      • This was reproduced on Derby & Postgres.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shayb Shay Bagants
              Reporter:
              uriahl Uriah Levy
              Votes:
              5 Vote for this issue
              Watchers:
              12 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: