Reputation: 11
I have a Kotlin RPC service that uses MongoDB Kotlin coroutine driver, but when my service uses any of the database functions, the code just stop it's execution (freezes). Here's a server code:
val port = ...
val json = ...
embeddedServer(Netty, port) {
install(RPC)
routing {
rpc("/") {
rpcConfig {
serialization {
json(json)
}
}
registerService<PlayerService> { ctx -> PlayerServiceImpl(ctx) }
}
}
}
Here's a MongoDB repository code:
val collectionName = ...
val entityClass = ...
val collection = database.database.getCollection(
collectionName,
entityClass.java
)
suspend fun findById(id: I) = collection.find(eq(id)).firstOrNull()
And the service code:
class PlayerServiceImpl(
override val coroutineContext: CoroutineContext
) : PlayerService {
override suspend fun findProfileById(id: String): ProfileData? {
// The next line never completes it's execution
val result = ProfileRepository.findById(id)
// So this line is unreachable
return result
}
}
The client code I think is ok, cause it executes the service function above.
So the problem is that the execution just stops when it reaches database logic. Any ideas why and how to fix that?
Upvotes: 0
Views: 23