Kjartan
06/25/2025, 5:50 AMsimon.vergauwen
06/25/2025, 6:27 AMsimon.vergauwen
06/25/2025, 6:28 AMKjartan
06/25/2025, 6:50 AMcleanup and was what lead me to this question. I'm currently using SuspendApp and it has worked nice, but with the new DI features in Ktor I was thinking about doing some refactoring towards using Ktor DI. I think it would be great with an update of the Ktor doc too, haven't looked too closely there yet, just read the release notes and got curious 🙂simon.vergauwen
06/30/2025, 7:18 AMmonitor.subscribe(ApplicationStopped) { closeable.close() }, beware of the order of closing. cleanup and ResourceScope do this automatically. Koin also supports onClose, and it has compile-time checks which Ktor doesn’t have atm.
We should probably add cleanup into server-core instead of just the DI module. If you want feel free to create a YT issue, or I can do it later ☺️phldavies
08/29/2025, 9:47 AMsimon.vergauwen
08/29/2025, 10:04 AMSuspendApp was build most of the required behavior was not yet implemented in Ktor 😅 (Neither did Spring). Currently both support this functionality.
> HTTP serving component
This doesn't feel correct to me either 😅 Application is not related to HTTP, or Routing. It's tightly coupled for convenience but they're isolated components. From coroutines POV Application is just SupervisorJob + state (environment). That is also reflected in how it shuts down.
Anyway, I personally prefer SuspendApp since it's a proper abstraction, and makes embeddedServer just another coroutine. I wish it was part of the KotlinX ecoystem and then Ktor could redefine this logic purely as a composition of coroutines.phldavies
08/29/2025, 10:37 AMSuspendApp (+ ResourceScope) is the ability to delay shutdown to allow for infra such as Load Balancers to unregister before the service starts rejecting requests.
And neither cleanup or monitor.subscribe allow for suspendful resource releasing.
I do like the idea of using Application as the core of a service and the http facet becoming just another coroutine - it would be nice to have a single Application with multiple ports too (to allow for scenarios like dedicated metrics/management ports, or separating ports for HTTP/GraphQL/gRPC/kRPC etc)simon.vergauwen
08/29/2025, 11:30 AMcleanup or monitor.subscribe allow for suspendful resource releasing.
Planned, but breaking changes are delaying this to next major version.simon.vergauwen
08/29/2025, 11:31 AMApplication as the core of a service and the http facet becoming just another coroutine - it would be nice to have a single Application with multiple ports too (to allow for scenarios like dedicated metrics/management ports, or separating ports for HTTP/GraphQL/gRPC/kRPC etc)
What do you mean? That's already possible today 😎simon.vergauwen
08/29/2025, 11:33 AM