Skip to content

Commit

Permalink
Potential workaround for concurrent enhancement race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed May 16, 2024
1 parent 2166451 commit 8f68f4e
Showing 1 changed file with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.quarkus.hibernate.orm.deployment.integration.QuarkusClassFileLocator;
import io.quarkus.hibernate.orm.deployment.integration.QuarkusEnhancementContext;
import net.bytebuddy.ClassFileVersion;
import net.bytebuddy.dynamic.ClassFileLocator;

/**
* Used to transform bytecode by registering to
Expand Down Expand Up @@ -101,8 +102,9 @@ public Enhancer getEnhancer() {
if (actualEnhancer == null) {
synchronized (this) {
if (actualEnhancer == null) {
EnhancerClassLocator modelPool = ModelTypePool.buildModelTypePool(QuarkusClassFileLocator.INSTANCE,
CORE_POOL);
EnhancerClassLocator modelPool = new QuarkusModelTypePool(
ModelTypePool.buildModelTypePool(QuarkusClassFileLocator.INSTANCE,
CORE_POOL));
actualEnhancer = PROVIDER.getEnhancer(QuarkusEnhancementContext.INSTANCE, modelPool);
}
}
Expand All @@ -111,4 +113,41 @@ public Enhancer getEnhancer() {
}
}

//This is most likely better solved within Hibernate ORM, but should do for now:
private static class QuarkusModelTypePool implements EnhancerClassLocator {

private final EnhancerClassLocator delegate;

private QuarkusModelTypePool(final EnhancerClassLocator delegate) {
this.delegate = delegate;
}

@Override
public void registerClassNameAndBytes(String s, byte[] bytes) {
this.delegate.registerClassNameAndBytes(s, bytes);
}

@Override
public void deregisterClassNameAndBytes(String s) {
//Don't do this: we'll have concurrent de-registrations, possibly for the same entry being
//processed by a different thread, when entities are listed as inner classes of other types
//which are also processed. This happens for example in Quarkus integration tests.
}

@Override
public ClassFileLocator asClassFileLocator() {
return delegate.asClassFileLocator();
}

@Override
public Resolution describe(String s) {
return delegate.describe(s);
}

@Override
public void clear() {
//nope
}
}

}

0 comments on commit 8f68f4e

Please sign in to comment.