Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1618

static structMap in FieldMetaData is not thread safe and can lead to deadlocks

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8
    • Fix Version/s: 0.9.3
    • Labels:
      None
    • Environment:

      jdk 1.6

      Description

      Generated thrift structs use static initializers to add metadata to the static 'structMap' field in FieldMetaData. Since the thrift structs may be separate classes, the static initializers can be executed on different threads. The addStructMetaDataMap method does not synchronize access and uses a standard HashMap which is not thread safe. This can lead to corruption of the structMap and in some cases deadlocks due to corrupt entries in the map during a put operation.

      The easy fix is to use a thread safe map for the structMap.

      Another fix is to just retrieve the field directly from the class in the 'getStructMetaDataMap' using reflection.

      I've confirmed the deadlock in 0.2. I looked at the 0.8 code and confirmed the bug is still present.

        Attachments

        1. ThriftDeadlock.java
          4 kB
          Mike Rettig

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              mrettig Mike Rettig
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: