JetBrains / Exposed

Kotlin SQL Framework
http://jetbrains.github.io/Exposed/
Apache License 2.0
8.41k stars 694 forks source link

Seems like an infinite recursion in 'match' sql-operator #978

Closed LoneEngineer closed 4 years ago

LoneEngineer commented 4 years ago

Version: 0.22.1

If I run query with 'match' operator, I got

Caused by: java.lang.StackOverflowError
    at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:163)
    at org.jetbrains.exposed.sql.transactions.TransactionManager$Companion.getManager(TransactionApi.kt:81)
    at org.jetbrains.exposed.sql.transactions.TransactionManager$Companion.currentOrNull(TransactionApi.kt:90)
    at org.jetbrains.exposed.sql.transactions.TransactionManager$Companion.current(TransactionApi.kt:92)
    at org.jetbrains.exposed.sql.vendors.DefaultKt.getCurrentDialect(Default.kt:669)
    at org.jetbrains.exposed.sql.SqlExpressionBuilderClass.match(SQLExpressionBuilder.kt:283)
    at org.jetbrains.exposed.sql.SqlExpressionBuilderClass.match(SQLExpressionBuilder.kt:283)
....

Issue seems to be here (in master version): https://github.com/JetBrains/Exposed/blob/cd6bb936b339bc0a55d2ae59ba71f027ea8d0504/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/SQLExpressionBuilder.kt#L288

Tapac commented 4 years ago

Could you please check with 0.26.1 and share a little bit longer stacktrace?

LoneEngineer commented 4 years ago

@Tapac Just checked with 0.26.1. Problem is still there. Stacktrace is changed a bit:

java.lang.StackOverflowError
    at |b|b|b(Coroutine boundary.|b(|b)
    at io.ktor.routing.Routing.executeResult(Routing.kt:147)
    at io.ktor.routing.Routing.interceptor(Routing.kt:34)
    at io.ktor.routing.Routing$Feature$install$1.invokeSuspend(Routing.kt:99)
    at io.ktor.features.ContentNegotiation$Feature$install$1.invokeSuspend(ContentNegotiation.kt:107)
    at io.ktor.features.StatusPages$interceptCall$2.invokeSuspend(StatusPages.kt:101)
    at io.ktor.features.StatusPages.interceptCall(StatusPages.kt:100)
    at io.ktor.features.StatusPages$Feature$install$2.invokeSuspend(StatusPages.kt:140)
    at io.ktor.features.CallLogging$Feature$install$1$invokeSuspend$$inlined$withMDC$1.invokeSuspend(CallLogging.kt:226)
    at io.ktor.features.CallLogging$Feature$install$1.invokeSuspend(CallLogging.kt:230)
    at io.ktor.server.testing.TestApplicationEngine$callInterceptor$1.invokeSuspend(TestApplicationEngine.kt:292)
    at io.ktor.server.testing.TestApplicationEngine$2.invokeSuspend(TestApplicationEngine.kt:50)
    at io.ktor.server.testing.TestApplicationEngine$handleRequest$pipelineJob$1.invokeSuspend(TestApplicationEngine.kt:290)
    at kotlinx.coroutines.DeferredCoroutine.await$suspendImpl(Builders.common.kt:99)
    at io.ktor.server.testing.TestApplicationEngine$handleRequest$1.invokeSuspend(TestApplicationEngine.kt:151)
Caused by: java.lang.StackOverflowError
    at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:163)
    at org.jetbrains.exposed.sql.transactions.TransactionManager$Companion.getManager(TransactionApi.kt:87)
    at org.jetbrains.exposed.sql.transactions.TransactionManager$Companion.currentOrNull(TransactionApi.kt:96)
    at org.jetbrains.exposed.sql.transactions.TransactionManager$Companion.current(TransactionApi.kt:98)
    at org.jetbrains.exposed.sql.vendors.DefaultKt.getCurrentDialect(Default.kt:735)
    at org.jetbrains.exposed.sql.ISqlExpressionBuilder$DefaultImpls.match(SQLExpressionBuilder.kt:292)
    at org.jetbrains.exposed.sql.SqlExpressionBuilder.match(SQLExpressionBuilder.kt:405)
    at org.jetbrains.exposed.sql.ISqlExpressionBuilder$DefaultImpls.match(SQLExpressionBuilder.kt:292)
    at org.jetbrains.exposed.sql.SqlExpressionBuilder.match(SQLExpressionBuilder.kt:405)
    at org.jetbrains.exposed.sql.ISqlExpressionBuilder$DefaultImpls.match(SQLExpressionBuilder.kt:292)
    at org.jetbrains.exposed.sql.SqlExpressionBuilder.match(SQLExpressionBuilder.kt:405)
... last two lines repeat a lot of time here ....

I think the issue with following code (even IDEA reports about 'recursive call') in org.jetbrains.exposed.sql.ISqlExpressionBuilder: image

Issue found in tests using H2 engine.

Tapac commented 4 years ago

Oh. now I see. It was broken with https://github.com/JetBrains/Exposed/issues/829. Will be fixed in next release. Thank you for a report.