Hi all, I'm having trouble with ktor's hot reload....
# ktor
r
Hi all, I'm having trouble with ktor's hot reload. My procedure is as follows: • run terminal> ./gradlew run • other terminal> ./gradlew -t build -x test -i • <hit endpoint> • run terminal> [123806.094] DefaultDispatcher-worker-1 co.example.TestController Hot reload test • <update log to log.error("Hot reload test 3")> • run terminal> ktor.application Changes in application detected. • run terminal> Responding at http://0.0.0.0:11111 • <hit endpoint> • run terminal> [123806.094] DefaultDispatcher-worker-1 co.example.TestController Hot reload test It appears to pick up the changes, but doesn't load in the updated classes. There doesn't seem to be a lot of configuration required, so I'm not sure what I could be missing?
a
Did you configure it as described in the documentation?
r
Yes, I have since looked at the change log, and see that there was a regression that was fixed in 1.5.3. So change detection now seems to work, but if I run the project without the shadow plugin, it doesn't respond to any requests 😕
a
I cannot reproduce it using Ktor 1.6.5 with my sample project. Could you please share your project?
r
Yes sure! I will just have to strip out all the code, which may take a while. I will post a zip with the project here when I'm done. Thanks!
Hi @Aleksei Tirman [JB], I have managed to isolate the issue. In the project, the routes are configured inside a singleton object, but inside the configuration scope of the embeddedServer constructor, the singleton appears to be recreated without it's routes. The configuration of the server is given below:
Copy code
<http://log.info|log.info>("RouteTypeMap size: ")
		<http://log.info|log.info>(RouteBuilder.routeTypeMap.size.toString())

		embeddedServer(
				Netty
			, port = 11111
		) {
			<http://log.info|log.info>("RouteTypeMap size in configuration block: ")
			<http://log.info|log.info>(RouteBuilder.routeTypeMap.size.toString())
which yields the following logs:
Copy code
RouteTypeMap size in Server:
870
RouteTypeMap size in configuration block:
0
I'm quite new to Kotlin, so don't really have a clue why the singleton seems to lose it's state?