ModuleClassLoader Deadlock

Hello,

I've got a module of mine using a REST API from the Ignition gateway, and I keep leaking database connections due to dead-locked threads from the Ignition Module class loader. Is there any way around this? Should I force this thread to use a separate class loader?

Full thread-dump of one of the dead-locked threads below.

{
  "name": "webserver-10520231",
  "id": 10520231,
  "state": "RUNNABLE",
  "daemon": false,
  "system": "Web API",
  "scope": "Gateway",
  "cpuUsage": 0,
  "lockedMonitors": [
    {
      "lock": "com.inductiveautomation.ignition.gateway.modules.NativeLibraryManagerImpl@4c686005",
      "frame": "java.base@11.0.15/java.lang.ClassLoader.loadClass(Unknown Source)"
    },
    {
      "lock": "com.inductiveautomation.ignition.gateway.modules.ModuleClassLoader@3e2f0cef",
      "frame": "java.base@11.0.15/java.lang.ClassLoader.loadClass(Unknown Source)"
    },
    {
      "lock": "com.inductiveautomation.ignition.gateway.modules.ModuleClassLoader@17281723"
    }
  ],
  "stacktrace": [
    "java.base@11.0.15/java.lang.ClassLoader.loadClass(Unknown Source)",
    "java.base@11.0.15/java.lang.ClassLoader.loadClass(Unknown Source)",
    "app//com.inductiveautomation.ignition.gateway.modules.ModuleClassLoader.loadClass(ModuleClassLoader.java:85)",
    "app//com.inductiveautomation.ignition.gateway.modules.ModuleClassLoader.loadClass(ModuleClassLoader.java:93)",
    "java.base@11.0.15/java.lang.ClassLoader.loadClass(Unknown Source)",
    "java.base@11.0.15/java.lang.Class.forName0(Native Method)",
    "java.base@11.0.15/java.lang.Class.forName(Unknown Source)",
    "org.hibernate.validator.internal.util.privilegedactions.LoadClass.loadNonValidatorClass(LoadClass.java:118)",
    "org.hibernate.validator.internal.util.privilegedactions.LoadClass.run(LoadClass.java:76)",
    "org.hibernate.validator.internal.util.privilegedactions.LoadClass.run(LoadClass.java:31)",
    "org.hibernate.validator.internal.metadata.core.ConstraintHelper.run(ConstraintHelper.java:1022)",
    "org.hibernate.validator.internal.metadata.core.ConstraintHelper.isClassPresent(ConstraintHelper.java:1007)",
    "org.hibernate.validator.internal.metadata.core.ConstraintHelper.isJavaMoneyInClasspath(ConstraintHelper.java:974)",
    "org.hibernate.validator.internal.metadata.core.ConstraintHelper.<init>(ConstraintHelper.java:324)",
    "org.hibernate.validator.internal.engine.ValidatorFactoryImpl.<init>(ValidatorFactoryImpl.java:146)",
    "org.hibernate.validator.HibernateValidator.buildValidatorFactory(HibernateValidator.java:38)",
    "org.hibernate.validator.internal.engine.ConfigurationImpl.buildValidatorFactory(ConfigurationImpl.java:386)",
    "javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:103)",
    "com.tamakicontrol.service.model.AbstractCrudService.createValidator(AbstractCrudService.java:46)",
    "com.tamakicontrol.service.model.AbstractCrudService.<init>(AbstractCrudService.java:39)",
    "com.tamakicontrol.service.model.productionmodel.ProductionModelService.<init>(ProductionModelService.java:44)",
    "com.tamakicontrol.service.model.productionmodel.ProductionModelService$$EnhancerByGuice$$36026832.<init>(<generated>)",
    "com.tamakicontrol.service.model.productionmodel.ProductionModelService$$EnhancerByGuice$$36026832.GUICE$TRAMPOLINE(<generated>)",
    "com.tamakicontrol.service.model.productionmodel.ProductionModelService$$EnhancerByGuice$$36026832$$Lambda$10844/0x000000080378cc40.apply(Unknown Source)",
    "com.google.inject.internal.ProxyFactory$ProxyConstructor.newInstance(ProxyFactory.java:183)",
    "com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:114)",
    "com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:91)",
    "com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:300)",
    "com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:40)",
    "com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:60)",
    "com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:113)",
    "com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:91)",
    "com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:300)",
    "com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:40)",
    "com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:60)",
    "com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:113)",
    "com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:91)",
    "com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:300)",
    "com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:40)",
    "com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:60)",
    "com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:113)",
    "com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:91)",
    "com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:300)",
    "com.google.inject.internal.InjectorImpl$1.get(InjectorImpl.java:1101)",
    "org.jvnet.hk2.guice.bridge.internal.GuiceServiceHk2Bean.create(GuiceServiceHk2Bean.java:90)",
    "org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:455)",
    "org.jvnet.hk2.guice.bridge.internal.GuiceScopeContext.findOrCreate(GuiceScopeContext.java:51)",
    "org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2102)",
    "org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:666)",
    "org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:54)",
    "org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:188)",
    "org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:211)",
    "org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:334)",
    "org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:463)",
    "org.glassfish.jersey.inject.hk2.RequestContext.findOrCreate(RequestContext.java:59)",
    "org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2102)",
    "org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:758)",
    "org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:721)",
    "org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:691)",
    "org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.getInstance(AbstractHk2InjectionManager.java:160)",
    "org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.getInstance(ImmediateHk2InjectionManager.java:30)",
    "org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:105)",
    "org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.getInstance(MethodHandler.java:260)",
    "org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:51)",
    "org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:86)",
    "org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:89)",
    "org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:89)",
    "org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:89)",
    "org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:69)",
    "org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:38)",
    "org.glassfish.jersey.process.internal.Stages.process(Stages.java:173)",
    "org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:247)",
    "org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)",
    "org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)",
    "org.glassfish.jersey.internal.Errors.process(Errors.java:292)",
    "org.glassfish.jersey.internal.Errors.process(Errors.java:274)",
    "org.glassfish.jersey.internal.Errors.process(Errors.java:244)",
    "org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)",
    "org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:234)",
    "org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:680)",
    "org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)",
    "org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)",
    "org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:366)",
    "org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:319)",
    "org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)",
    "app//com.inductiveautomation.ignition.gateway.bootstrap.MapServlet.service(MapServlet.java:86)",
    "app//org.eclipse.jetty.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1450)",
    "app//org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799)",
    "app//org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1631)",
    "app//org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:548)",
    "app//org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)",
    "app//org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:600)",
    "app//org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)",
    "app//org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)",
    "app//org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624)",
    "app//org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)",
    "app//org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1440)",
    "app//org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)",
    "app//org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501)",
    "app//org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594)"
  ]
},

Are you sure you have a deadlock? You've only posted one thread. Does the full thread dump actually indicate a deadlock between 2 or more threads at the top?

Sorry it was my mistake... I think I just happened to grab a copy of a thread dump that showed 2 different threads queuing for the same lock and I didn't notice it. No deadlocks though.