https://kotlinlang.org logo
#ktor
Title
# ktor
i

ishitatsuyuki

02/25/2022, 8:27 AM
Has anyone managed to do auto-reload with
embeddedServer
? There are two serious issues: 1. The documentation doesn't mention that the reloader only works if the
module
parammeter to
embeddedServer
refers to a function (if you use the lambda in attempt for simplicity, it doesn't work). 2. The server appears to break and start giving empty responses under some race condition, maybe if another HTTP request arrive during the restart? (still debugging)
For the second one, I don't know if it's relevant that I'm initializing HikariCP, Flyway and jOOQ inside the
module()
call.
Looks like the race condition has something to do with high system load; I was compiling Firefox when I had the issue and now that the load is gone the reload seems to be mostly fine. As for shutdown cleanup, I've registered a plugin that registers a shutdown hook to call close() on HikariCP.
Looking at ApplicationEngineEnvironmentReloading, my guess is that it's prooobably a deadlock... ReentrantReadWriteLock is in general not very pleasant to reason about
Question: is it possible for a reload to be initiated from two threads simultaneously? (The actual reload is protected by write locks, but the processing before that might be racy) Edit: If both threads attempt to reload, then they might deadlock as they try to upgrade their read locks to write locks but neither will success (due to the other thread holding a read lock).
a

Aleksei Tirman [JB]

02/25/2022, 9:18 AM
@e5l
3 Views