Deadlock during static initialization
Expected behavior
Perhaps similar or the same as #8226 but perhaps not. I have a deadlock during startup in a Kotlin Coroutines environment where two background loops accessing the database are started at the same time.
Actual behavior
Thread A attempts to use DSL.using(...). This triggers for DefaultDSLContext. DefaultDSLContext then attempts to load SQLDataType via Class.forName.
Thread B attempts to access a generated Tables class. This triggers for Tools. Tools (at line 3607) calls DSL.using(...).
A deadlock occurs because DSL.using is waiting for DefaultDSLContext to finish initializing, while DefaultDSLContext is deep in AbstractDataType logic that appears to conflict with the locks held by the Tools initialization.
Coroutine StandaloneCoroutine{Active}@2c70d110, state: RUNNING
at org.jooq.impl.AbstractDataType.getTypeName(AbstractDataType.java:527)
at org.jooq.impl.DefaultDataType.getTypeName(DefaultDataType.java:136)
at org.jooq.impl.ArrayDataType.<init>(ArrayDataType.java:63)
at org.jooq.impl.AbstractDataType.getArrayDataType(AbstractDataType.java:611)
at org.jooq.impl.DefaultDataType.getArrayDataType(DefaultDataType.java:136)
at org.jooq.impl.DefaultDataType.<init>(DefaultDataType.java:392)
... (constructors)
at org.jooq.impl.BuiltInDataType.<init>(BuiltInDataType.java:60)
at org.jooq.impl.SQLDataType.<clinit>(SQLDataType.java:161)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:377)
at org.jooq.impl.DefaultDSLContext.<clinit>(DefaultDSLContext.java:5265)
at org.jooq.impl.DSL.using(DSL.java:886)
at mypackage.datastore.jooq.JooqsKt.dslContext(Jooqs.kt:22)
Coroutine StandaloneCoroutine{Active}@218c7b99, state: RUNNING
at org.jooq.impl.DSL.using(DSL.java:886)
at org.jooq.impl.Tools.<clinit>(Tools.java:3607)
at org.jooq.impl.FieldsImpl.<init>(FieldsImpl.java:85)
at org.jooq.impl.TableImpl.<init>(TableImpl.java:245)
at mypackage.sql.tables._EnumTypeHolder.<init>(_EnumTypeHolder.java:71)
... (generated code)
at mypackage.sql.Tables.<clinit>(Tables.java:130)
at mypackage.Background2.doJob(Background2.kt:155)The code that is doing Tables.<clinit> is basically creating some tables with aliases e.g.:
val table1 = TABLE1.`as`("t1")
val table2 = TABLE2.`as`("t2")Steps to reproduce the problem
Code gen config:
name = "org.jooq.codegen.DefaultGenerator"
database.apply {
name = "org.jooq.meta.postgres.PostgresDatabase"
inputSchema = "public"
forcedTypes.addAll(
arrayOf(
ForcedType()
.withName("text")
.withIncludeExpression(".*")
.withIncludeTypes("CLOB"),
// this *should* be included by default by jooq-postgres-extensions, but it isn't?
ForcedType()
.withUserType("java.lang.String")
.withBinding("org.jooq.postgres.extensions.bindings.CitextBinding")
.withIncludeTypes("citext")
).toList()
)
}
generate.apply {
isDeprecated = false
isRecords = true
isImmutablePojos = false
isFluentSetters = true
isJsonTypes = true
}
target.apply {
packageName = "mypackage.sql"
}
strategy.name = "org.jooq.codegen.DefaultGeneratorStrategy"jOOQ Version
3.20.9
Database product and version
PostgreSQL 17.6 on x86_64-pc-linux-gnu, compiled by Debian clang version 12.0.1, 64-bit
Java Version
openjdk version "17.0.17"
JDBC / R2DBC driver name and version (include name if unofficial driver)
org.postgresql:postgresql:42.2.26
Source: jOOQ/jOOQ