You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Mike Rettig (JIRA)" <ji...@apache.org> on 2012/05/30 17:51:23 UTC

[jira] [Created] (THRIFT-1618) static structMap in FieldMetaData is not thread safe and can lead to deadlocks

Mike Rettig created THRIFT-1618:
-----------------------------------

             Summary: static structMap in FieldMetaData is not thread safe and can lead to deadlocks
                 Key: THRIFT-1618
                 URL: https://issues.apache.org/jira/browse/THRIFT-1618
             Project: Thrift
          Issue Type: Bug
    Affects Versions: 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2
         Environment: jdk 1.6
            Reporter: Mike Rettig
            Priority: Critical


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. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (THRIFT-1618) static structMap in FieldMetaData is not thread safe and can lead to deadlocks

Posted by "Mike Rettig (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-1618?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mike Rettig updated THRIFT-1618:
--------------------------------

    Component/s: Java - Library
                 Java - Compiler
    
> static structMap in FieldMetaData is not thread safe and can lead to deadlocks
> ------------------------------------------------------------------------------
>
>                 Key: THRIFT-1618
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1618
>             Project: Thrift
>          Issue Type: Bug
>          Components: Java - Compiler, Java - Library
>    Affects Versions: 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8
>         Environment: jdk 1.6
>            Reporter: Mike Rettig
>            Priority: Critical
>
> 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. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (THRIFT-1618) static structMap in FieldMetaData is not thread safe and can lead to deadlocks

Posted by "Mike Rettig (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1618?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13471364#comment-13471364 ] 

Mike Rettig commented on THRIFT-1618:
-------------------------------------

ThriftDeadlock.java was attached on september 27th. It just needs a jar that contains some thrift classes and it should deadlock just about every time it runs.
                
> static structMap in FieldMetaData is not thread safe and can lead to deadlocks
> ------------------------------------------------------------------------------
>
>                 Key: THRIFT-1618
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1618
>             Project: Thrift
>          Issue Type: Bug
>          Components: Java - Compiler, Java - Library
>    Affects Versions: 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8
>         Environment: jdk 1.6
>            Reporter: Mike Rettig
>            Priority: Critical
>         Attachments: ThriftDeadlock.java
>
>
> 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. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (THRIFT-1618) static structMap in FieldMetaData is not thread safe and can lead to deadlocks

Posted by "Roger Meier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1618?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13471313#comment-13471313 ] 

Roger Meier commented on THRIFT-1618:
-------------------------------------

do you have a patch or/and a test case?
                
> static structMap in FieldMetaData is not thread safe and can lead to deadlocks
> ------------------------------------------------------------------------------
>
>                 Key: THRIFT-1618
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1618
>             Project: Thrift
>          Issue Type: Bug
>          Components: Java - Compiler, Java - Library
>    Affects Versions: 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8
>         Environment: jdk 1.6
>            Reporter: Mike Rettig
>            Priority: Critical
>         Attachments: ThriftDeadlock.java
>
>
> 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. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (THRIFT-1618) static structMap in FieldMetaData is not thread safe and can lead to deadlocks

Posted by "Mike Rettig (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-1618?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mike Rettig updated THRIFT-1618:
--------------------------------

    Attachment: ThriftDeadlock.java

Here is my repro. You will need to provide your own jar that includes some generated thrift classes.
                
> static structMap in FieldMetaData is not thread safe and can lead to deadlocks
> ------------------------------------------------------------------------------
>
>                 Key: THRIFT-1618
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1618
>             Project: Thrift
>          Issue Type: Bug
>          Components: Java - Compiler, Java - Library
>    Affects Versions: 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8
>         Environment: jdk 1.6
>            Reporter: Mike Rettig
>            Priority: Critical
>         Attachments: ThriftDeadlock.java
>
>
> 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. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira