orika-mapper / orika

Simpler, better and faster Java bean mapping framework
http://orika-mapper.github.io/orika-docs/
Apache License 2.0
1.29k stars 268 forks source link

deadlock in orika 1.5.4 #365

Open olliim2m opened 3 years ago

olliim2m commented 3 years ago

Using Quarkus 1.10.x and Orika 1.5.4

We see a deadlock occurring just after the application has been started. The application receives two rest calls, collects data from the database and maps the data using two orika mapper. In this scenario the application hangs.

Found one Java-level deadlock:
=============================
"executor-thread-1":
  waiting to lock monitor 0x000056353db6be00 (object 0x00000000e5769f40, a ma.glasnost.orika.metadata.Type),
  which is held by "executor-thread-2"
"executor-thread-2":
  waiting to lock monitor 0x000056353db6a400 (object 0x00000000e55eee48, a ma.glasnost.orika.metadata.Type),
  which is held by "executor-thread-1"
Java stack information for the threads listed above:
===================================================
"executor-thread-1":
    at ma.glasnost.orika.metadata.TypeKey.getTypeIndex(TypeKey.java:60)
    - waiting to lock <0x00000000e5769f40> (a ma.glasnost.orika.metadata.Type)
    at ma.glasnost.orika.metadata.TypeKey.valueOf(TypeKey.java:51)
    at ma.glasnost.orika.metadata.TypeFactory.intern(TypeFactory.java:437)
    at ma.glasnost.orika.metadata.TypeFactory.valueOf(TypeFactory.java:100)
    at ma.glasnost.orika.metadata.TypeFactory.valueOf(TypeFactory.java:124)
    at ma.glasnost.orika.property.PropertyResolver.resolveGenericType(PropertyResolver.java:193)
    at ma.glasnost.orika.property.PropertyResolver.resolvePropertyType(PropertyResolver.java:330)
    at ma.glasnost.orika.property.PropertyResolver.processProperty(PropertyResolver.java:266)
    at ma.glasnost.orika.property.IntrospectorPropertyResolver.collectProperties(IntrospectorPropertyResolver.java:105)
    at ma.glasnost.orika.property.PropertyResolver.getProperties(PropertyResolver.java:128)
    - locked <0x00000000e55eee48> (a ma.glasnost.orika.metadata.Type)
    at ma.glasnost.orika.metadata.ClassMapBuilder.<init>(ClassMapBuilder.java:122)
    at ma.glasnost.orika.metadata.ClassMapBuilder$Factory.newClassMapBuilder(ClassMapBuilder.java:70)
    at ma.glasnost.orika.metadata.ClassMapBuilderFactory.getNewClassMapBuilder(ClassMapBuilderFactory.java:142)
    - locked <0x00000000e1783b60> (a ma.glasnost.orika.metadata.ClassMapBuilder$Factory)
    at ma.glasnost.orika.metadata.ClassMapBuilderFactory.map(ClassMapBuilderFactory.java:153)
    at ma.glasnost.orika.impl.DefaultMapperFactory.classMap(DefaultMapperFactory.java:1562)
    at ma.glasnost.orika.impl.DefaultMapperFactory.classMap(DefaultMapperFactory.java:1575)
    at de.m2mgate.burg.api.mapper.ExtendedFirmwareMapper.initMapper(ExtendedFirmwareMapper.java:42)
"executor-thread-2":
    at ma.glasnost.orika.metadata.TypeKey.getTypeIndex(TypeKey.java:60)
    - waiting to lock <0x00000000e55eee48> (a ma.glasnost.orika.metadata.Type)
    at ma.glasnost.orika.metadata.TypeKey.valueOf(TypeKey.java:51)
    at ma.glasnost.orika.metadata.TypeFactory.intern(TypeFactory.java:437)
    at ma.glasnost.orika.metadata.TypeFactory.valueOf(TypeFactory.java:100)
    at ma.glasnost.orika.metadata.TypeFactory.valueOf(TypeFactory.java:124)
    at ma.glasnost.orika.property.PropertyResolver.resolveGenericType(PropertyResolver.java:193)
    at ma.glasnost.orika.property.PropertyResolver.resolvePropertyType(PropertyResolver.java:330)
    at ma.glasnost.orika.property.PropertyResolver.processProperty(PropertyResolver.java:266)
    at ma.glasnost.orika.property.IntrospectorPropertyResolver.collectProperties(IntrospectorPropertyResolver.java:105)
    at ma.glasnost.orika.property.PropertyResolver.getProperties(PropertyResolver.java:128)
    - locked <0x00000000e5769f40> (a ma.glasnost.orika.metadata.Type)
    at ma.glasnost.orika.metadata.ClassMapBuilder.<init>(ClassMapBuilder.java:122)
    at ma.glasnost.orika.metadata.ClassMapBuilder$Factory.newClassMapBuilder(ClassMapBuilder.java:70)
    at ma.glasnost.orika.metadata.ClassMapBuilderFactory.getNewClassMapBuilder(ClassMapBuilderFactory.java:142)
    - locked <0x00000000e178eff8> (a ma.glasnost.orika.metadata.ClassMapBuilder$Factory)
    at ma.glasnost.orika.metadata.ClassMapBuilderFactory.map(ClassMapBuilderFactory.java:153)
    at ma.glasnost.orika.impl.DefaultMapperFactory.classMap(DefaultMapperFactory.java:1562)
    at ma.glasnost.orika.impl.DefaultMapperFactory.classMap(DefaultMapperFactory.java:1575)
    at de.m2mgate.burg.api.mapper.HardwareMapper.initMapper(HardwareMapper.java:30)

Both mappers are initialized in a method annotated with @PostConstruct.

As a workaround we annotated the mappers with

@Singleton
@Startup

Now the initailization occurs during the startup phase of the application and the deadlock does not seem to occur.

qixiaobo commented 3 years ago

We meet too with version 1.5.0