Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PropertyNamingStrategy class initialization depends on its subclass, this can lead to class loading deadlock #2715

Closed
fangwentong opened this issue May 9, 2020 · 6 comments

Comments

@fangwentong
Copy link

If a class refer to its subclasses in its static initializers or in static fields, this references can cause JVM-level deadlocks in multithreaded environment, when one thread tries to load superclass and another thread tries to load subclass at the same time.

See: https://bugs.openjdk.java.net/browse/JDK-8037567

The following demo code can reproduce this deadlock

public class ClassInitDeadLock {

    public static void main(String[] args) throws InterruptedException {
        Thread threadA = new Thread(new Runnable() {
            @Override
            public void run() {
                // trigger supper class initialize
                PascalCaseStrategy strategy = PropertyNamingStrategy.PASCAL_CASE_TO_CAMEL_CASE;
            }
        }, "Thread-A");

        Thread threadB = new Thread(new Runnable() {
            @Override
            public void run() {
                // trigger sub class initialize
                PascalCaseStrategy strategy = new PascalCaseStrategy();
            }
        }, "Thread-B");

        threadA.start();
        Thread.sleep(100);
        threadB.start();
    }

    public static class PropertyNamingStrategy {
        static {
            try {
                // sleep 1s for deadlock reproduction
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // ignore
            }
        }

        public static final PascalCaseStrategy PASCAL_CASE_TO_CAMEL_CASE = new PascalCaseStrategy();
    }

    public static class PascalCaseStrategy extends PropertyNamingStrategy {
    }
}

When the demo program ClassInitDeadLock started, it could not exit automatically. Thread-A holding PropertyNamingStrategy class , and waiting PascalCaseStrategy class initialize, while Thread-B holding PascalCaseStrategy class, and waiting PropertyNamingStrategy class initialize, deadlock occurred!

jstack of these two thread:

"Thread-A" #11 prio=5 os_prio=31 tid=0x00007fa8c29d8000 nid=0xa803 in Object.wait() [0x000070000a4c4000]
   java.lang.Thread.State: RUNNABLE
	at ClassInitDeadLock$PropertyNamingStrategy.<clinit>(ClassInitDeadLock.java:35)
	at ClassInitDeadLock$1.run(ClassInitDeadLock.java:8)
	at java.lang.Thread.run(Thread.java:748)

"Thread-B" #12 prio=5 os_prio=31 tid=0x00007fa8c4a9b800 nid=0x5603 in Object.wait() [0x000070000a5c7000]
   java.lang.Thread.State: RUNNABLE
	at ClassInitDeadLock$2.run(ClassInitDeadLock.java:16)
	at java.lang.Thread.run(Thread.java:748)

In the actual environment, PropertyNamingStrategy and its subclass defined in jackson-databind initialize very fast, so It's hard to produce the scene that multithread load superclass and subclass at the same time.

I happened to meet this deadlock recently, It turn out to be JsonErrorUnmarshaller.java#L37 defined in aws-java-sdk-core, trying to initialize subclass PascalCaseStrategy, at the same time, another thread is initilizing superclass PropertyNamingStrategy

private static final ObjectMapper MAPPER = new ObjectMapper().configure(
        DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).setPropertyNamingStrategy(
        new PascalCaseStrategy());
@cowtowncoder
Copy link
Member

Interesting. Thank you for reporting this, sounds like a potentially severe issue.

Do you know version of Jackson problem was encountered with? (AWS jdk core used relatively old version last I checked, 2.6.7?, but that was a while ago).
I assume issue has been around for a while but just wanted to check.

@cowtowncoder
Copy link
Member

Also... may be really really difficult to actually resolve, wrt backwards compatibility problems.

@fangwentong
Copy link
Author

fangwentong commented May 9, 2020

As a workarround, we can change the code of aws-java-sdk-core, new PascalCaseStrategy() => PropertyNamingStrategy.PASCAL_CASE_TO_CAMEL_CASE, this change can bypass the problem.

@cowtowncoder
Copy link
Member

cowtowncoder commented May 9, 2020

@fangwentong Yes. I think for databind itself, will probably need to introduce something like PropertyNamingStrategies to hold instances (which would have been good to do from beginning as a pattern). And then deprecate sub-type static instance.

@fangwentong
Copy link
Author

OK, thanks, backwards compatibility is really important,I'll create a PR to aws-java-sdk-core.

fangwentong added a commit to fangwentong/aws-sdk-java that referenced this issue May 9, 2020
bypass the potential deadlock when PropertyNamingStrategy class initialization
see: FasterXML/jackson-databind#2715
fangwentong added a commit to fangwentong/ksc-sdk-java that referenced this issue May 9, 2020
bypass the potential deadlock when PropertyNamingStrategy class initialization
see: FasterXML/jackson-databind#2715
@cowtowncoder cowtowncoder added 2.12 and removed 2.10 labels May 23, 2020
@cowtowncoder
Copy link
Member

Unfortunately I think the solution can only go in 2.12, as I need to add PropertyNamingStrategies as the place for static instances, deprecate existing entries; that is, making API changes that need to go in a new minor version.

cowtowncoder added a commit that referenced this issue Aug 25, 2020
@cowtowncoder cowtowncoder changed the title PropertyNamingStrategy class initialization depends on its subclass, this might lead to class loading deadlock PropertyNamingStrategy class initialization depends on its subclass, this can lead to class loading deadlock Aug 25, 2020
cowtowncoder added a commit that referenced this issue Oct 13, 2020
adhirajsinghchauhan added a commit to oxygen-updater/oxygen-updater that referenced this issue Dec 10, 2020
Also replaced Jackson's PropertyNamingStrategy deprecation: FasterXML/jackson-databind#2715
rhowe added a commit to rhowe/dropwizard that referenced this issue Jan 3, 2021
…akeCaseStrategy

This has been replaced by PropertyNamingStrategies.SnakeCaseStrategy due to a
possible classloader deadlock:
FasterXML/jackson-databind#2715
joschi pushed a commit to dropwizard/dropwizard that referenced this issue Jan 4, 2021
…3634)

This has been replaced by `PropertyNamingStrategies.SnakeCaseStrategy` due to a possible class loader deadlock.

Refs FasterXML/jackson-databind#2715
joschi pushed a commit to dropwizard/dropwizard that referenced this issue Jan 6, 2021
…3634)

This has been replaced by `PropertyNamingStrategies.SnakeCaseStrategy` due to a possible class loader deadlock.

Refs FasterXML/jackson-databind#2715

(cherry picked from commit 710c9a7)
finaglehelper pushed a commit to twitter/util that referenced this issue Feb 24, 2022
Problem

In release 2.12,  Jackson introduced `PropertyNamingStrategies` as a work-around
for [#2715](FasterXML/jackson-databind#2715) which deprecated using the like `PropertyNamingStrategy` static fields.

Solution

Move to using the equivalent static fields in `PropertyNamingStrategies`.

Result

Less deprection tech-debt.

Differential Revision: https://phabricator.twitter.biz/D838232
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
… (#3634)

    This has been replaced by `PropertyNamingStrategies.SnakeCaseStrategy` due to a possible class loader deadlock.

    Refs FasterXML/jackson-databind#2715
patelila added a commit to hmcts/ccd-definition-store-api that referenced this issue May 13, 2024
…ropertyNamingStrategy$SnakeCaseStrategy PropertyNamingStrategy.SnakeCaseStrategy is used but it has been deprecated due to risk of deadlock. Consider using PropertyNamingStrategies.SnakeCaseStrategy instead. See FasterXML/jackson-databind#2715 for more details.
patelila added a commit to hmcts/ccd-definition-store-api that referenced this issue May 23, 2024
…ropertyNamingStrategy$SnakeCaseStrategy PropertyNamingStrategy.SnakeCaseStrategy is used but it has been deprecated due to risk of deadlock. Consider using PropertyNamingStrategies.SnakeCaseStrategy instead. See FasterXML/jackson-databind#2715 for more details.
snazy added a commit to snazy/iceberg that referenced this issue May 25, 2024
Following warning is always printed when using Iceberg REST clients:
```
PropertyNamingStrategy.KebabCaseStrategy is used but it has been deprecated due to risk of deadlock. Consider using PropertyNamingStrategies.KebabCaseStrategy instead. See FasterXML/jackson-databind#2715 for more details.
```
Fokko pushed a commit to apache/iceberg that referenced this issue May 27, 2024
Following warning is always printed when using Iceberg REST clients:
```
PropertyNamingStrategy.KebabCaseStrategy is used but it has been deprecated due to risk of deadlock. Consider using PropertyNamingStrategies.KebabCaseStrategy instead. See FasterXML/jackson-databind#2715 for more details.
```
ledbutter added a commit to ledbutter/unitycatalog that referenced this issue Jun 21, 2024
`PropertyNamingStrategy` is
[deprecated](FasterXML/jackson-databind#2715)
due to the possibility of class loading deadlock. This change simply
switches to the recommended `PropertyNamingStrategies` equivalent.
tdas added a commit to unitycatalog/unitycatalog that referenced this issue Jun 27, 2024
**PR Checklist**

- [x] A description of the changes is added to the description of this
PR.
- [ ] If there is a related issue, make sure it is linked to this PR.
- [ ] If you've fixed a bug or added code that should be tested, add
tests!
- [ ] If you've added or modified a feature, documentation in `docs` is
updated

**Description of changes**

`PropertyNamingStrategy` is
[deprecated](FasterXML/jackson-databind#2715)
due to the possibility of class loading deadlock. This change simply
switches to the recommended `PropertyNamingStrategies` equivalent.

Co-authored-by: Tathagata Das <tathagata.das1565@gmail.com>
haogang pushed a commit to unitycatalog/unitycatalog that referenced this issue Jul 24, 2024
**PR Checklist**

- [X] A description of the changes is added to the description of this
PR.
- [X] If there is a related issue, make sure it is linked to this PR.
- [ ] If you've fixed a bug or added code that should be tested, add
tests!
- [ ] If you've added or modified a feature, documentation in `docs` is
updated

**Description of changes**

https://github.com/koalaman/shellcheck/wiki/SC2068
> Double quotes around $@ (and similarly, ${array[@]}) prevents globbing
and word splitting of individual elements, while still expanding to
multiple separate arguments.

**Testing Changes**
```
bin/uc
Please provide a entity.

Usage: bin/uc <entity> <operation> [options]
Entities: schema, volume, catalog, function, table

By default, the client will connect to UC running locally at http://localhost:8080

To connect to specific UC server, use --server https://<host>

Currently, auth using bearer token is supported. Please specify the token via --auth_token <PAT Token>

For detailed help on entity specific operations, use bin/uc <entity> --help
~/unitycatalog git:[double_quote_array_expansion]
bin/uc schema --help
Please provide a valid sub-command for schema.
Valid sub-commands for schema are: get, create, update, list, delete
For detailed help on schema sub-commands, use bin/uc schema <sub-command> --help
~/unitycatalog git:[double_quote_array_expansion]
bin/uc schema get --help
Usage: bin/uc schema get [options]
Required Params:
  --full_name The full name of the table. The full name is the concatenation of the catalog name, schema name, and table/volume name separated by a dot. For example, catalog_name.schema_name.table_name.
Optional Params:
~/unitycatalog git:[double_quote_array_expansion]
bin/uc schema list
All required parameters are not provided.
Usage: bin/uc schema list [options]
Required Params:
  --catalog The name of the catalog.
Optional Params:
  --max_results The maximum number of results to return.
~/unitycatalog git:[double_quote_array_expansion]
bin/uc catelog list
Invalid entity provided.

Usage: bin/uc <entity> <operation> [options]
Entities: schema, volume, catalog, function, table

By default, the client will connect to UC running locally at http://localhost:8080

To connect to specific UC server, use --server https://<host>

Currently, auth using bearer token is supported. Please specify the token via --auth_token <PAT Token>

For detailed help on entity specific operations, use bin/uc <entity> --help
~/unitycatalog git:[double_quote_array_expansion]
bin/uc catalog list
...
```

```
bin/start-uc-server 44
Jul 07, 2024 10:47:24 PM com.fasterxml.jackson.databind.PropertyNamingStrategy$PropertyNamingStrategyBase <init>
WARNING: PropertyNamingStrategy.KebabCaseStrategy is used but it has been deprecated due to risk of deadlock. Consider using PropertyNamingStrategies.KebabCaseStrategy instead. See FasterXML/jackson-databind#2715 for more details.
################################################################### 
#  _    _       _ _            _____      _        _              #
# | |  | |     (_) |          / ____|    | |      | |             #
# | |  | |_ __  _| |_ _   _  | |     __ _| |_ __ _| | ___   __ _  #
# | |  | | '_ \| | __| | | | | |    / _` | __/ _` | |/ _ \ / _` | #
# | |__| | | | | | |_| |_| | | |___| (_| | || (_| | | (_) | (_| | #
#  \____/|_| |_|_|\__|\__, |  \_____\__,_|\__\__,_|_|\___/ \__, | #
#                      __/ |                                __/ | #
#                     |___/              vv0.1.0-SNAPSHOT  |___/  #
###################################################################

#68
patelila added a commit to hmcts/ccd-data-store-api that referenced this issue Aug 12, 2024
…been deprecated due to risk of deadlock. Consider using PropertyNamingStrategies.SnakeCaseStrategy instead. See FasterXML/jackson-databind#2715 for more details.
patelila added a commit to hmcts/ccd-data-store-api that referenced this issue Aug 15, 2024
…y.SnakeCaseStrategy is used but it has been deprecated due to risk of deadlock. Consider using PropertyNamingStrategies.SnakeCaseStrategy instead. See FasterXML/jackson-databind#2715 for more details.
sasankpagolu pushed a commit to sasankpagolu/iceberg that referenced this issue Oct 27, 2024
Following warning is always printed when using Iceberg REST clients:
```
PropertyNamingStrategy.KebabCaseStrategy is used but it has been deprecated due to risk of deadlock. Consider using PropertyNamingStrategies.KebabCaseStrategy instead. See FasterXML/jackson-databind#2715 for more details.
```
ankita-srivastava009 pushed a commit to hmcts/ccd-definition-store-api that referenced this issue Nov 12, 2024
…essTypeRoles associated for CaseTypeId (#1468)

* Changes so easy to run single FT

* Using PropertyNamingStrategies.SnakeCaseStrategy because of c.f.j.d.PropertyNamingStrategy$SnakeCaseStrategy PropertyNamingStrategy.SnakeCaseStrategy is used but it has been deprecated due to risk of deadlock. Consider using PropertyNamingStrategies.SnakeCaseStrategy instead. See FasterXML/jackson-databind#2715 for more details.

* changes to query for POST /retrieve-access-types does retrieve AccessType and AccessTypeRoles associated for CaseTypeId

* FT for multiple jurisdiction and removing accessType (multiple) versionsfor POST /retrieve-access-types does retrieve AccessType and AccessTypeRoles associated for CaseTypeId

* removed as commited by mistake

* Update build.gradle revert version

To check if tests pass and not get the json parser error

* fix for error Errror at ✽.an appropriate test context as detailed in the test data source(file:///Users/ilapatel/Documents/Work/repos/ccd-definition-store-api/aat/src/aat/resources/features/F-082/F-082.feature:7)
              Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('{' (code 123)): was expecting double-quote to start field name
               at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 69, column: 13]
                  at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2481)

* Modified FT 110.6

* CCD-test-definition using CCD_BEFTA_RM_CT_JURISDICTION1 which has cast_type removed and Modified FT 110.1a

* CCD-test-definition using CCD_BEFTA_RM_CT_JURISDICTION1 which has cast_type removed and Modified FT 110.1a

* Version change CCD-test-definition using CCD_BEFTA_RM_CT_JURISDICTION1 which has cast_type removed and Modified FT 110.1a

* remove mistaken typeo

* empty commit to trigger build

* version change for ccd-test-definition

* Fixing ERROR [main] uk.gov.hmcts.befta.util.MapVerifierjava.lang.NullPointerException: Cannot invoke "Object.toString()" because "idElementValue" is null

* Fix for `__elementId__` to field 'accessTypes.roles

* Fix for `__elementId__` to field 'accessTypes.roles

* Fix for `__elementId__` to field 'accessTypes.roles

* Fix Failed FT's

* Fix Failed FT's

* Ccd 5647 mismatch for CCD-5233 (#1494)

* version bump +  Missing bits +  spelling typo

* Change roles to ordered

* changed Respondant to Respondent

* changed Respondant to Respondent

* changed Respondant to Respondent

* empty commit to trigger build

* channged ordering and caseType name

* changed ordering and caseType name

* changed ordering and caseType name

* empty commit to trigger build

* changed ordering and caseType name

* changed ordering and caseType name

* Use pr-1468 instead of pr-575
and ccd-data-store-api-pr-2462-es-master instead of ccd-data-store-api-pr-1260-es-master

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* ordered ordering changed
and outputing env.DEFINITION_STORE_URL_BASE

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* reverted ordering as pipeline complaining

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* added checkstyle

* Changing the order

* Changing the order

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* revert change to be same as master

* use  ccd-data-store-api-pr-2472-es-master

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* change order as @F-080 @S-080.1 FT test fails as it is expecting ordered response

* change order as @F-080 @S-080.1 FT test fails as it is expecting ordered response

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

* empty commit to trigger build

---------

Co-authored-by: Dinesh Patel <dinesh1.patel@btinternet.com>
Co-authored-by: RebeccaBaker <38425793+RebeccaBaker@users.noreply.github.com>
Co-authored-by: bharatkumarpatel1 <Bharatkumar.Patel1@HMCTS.NET>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants