Skip to content

[Bug] Leaked SuspendAppShutdown / thrown on SIGTERM #3849

@alexandru

Description

@alexandru

I have a Ktor server that, when stopped via SIGTERM, throws an exception:

2026-01-17 18:19:24.273 ERROR [DefaultDispatcher-worker-6] Main - Application failed to start
arrow.continuations.SuspendAppShutdown: SuspendApp shutting down.
	at arrow.continuations.SuspendAppKt$SuspendApp$2$1$result$1$unregister$1$1.invokeSuspend(SuspendApp.kt:37)
	at arrow.continuations.SuspendAppKt$SuspendApp$2$1$result$1$unregister$1$1.invoke(SuspendApp.kt)
	at arrow.continuations.SuspendAppKt$SuspendApp$2$1$result$1$unregister$1$1.invoke(SuspendApp.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndspatched(Undispatched.kt:66)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:50)
	at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:149)
	at kotlinx.coroutines.TimeoutKt.withTimeout(Timeout.kt:44)
	at kotlinx.coroutines.TimeoutKt.withTimeout-KLykuaI(Timeout.kt:72)
	at arrow.continuations.SuspendAppKt$SuspendApp$2$1$result$1$unregister$1.invokeSuspend(SuspendApp.kt:36)
	at arrow.continuations.SuspendAppKt$SuspendApp$2$1$result$1$unregister$1.invoke(SuspendApp.kt)
	at arrow.continuations.SuspendAppKt$SuspendApp$2$1$result$1$unregister$1.invoke(SuspendApp.kt)
	at arrow.continuations.JvmProcess$onShutdown$shutdown$1.invokeSuspend(Enviroment.jvm.kt:22)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:263)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:94)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:70)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:48)
	at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
	at arrow.continuations.JvmProcess.onShutdown$shutdown(Enviroment.jvm.kt:19)
	at java.base/java.lang.Thread.run(Unknown Source)
2026-01-17 18:19:24.279 INFO  [DefaultDispatcher-worker-6] io.ktor.server.Application - prewait delay of 30000ms, turn it off using io.ktor.development=true

I don't know how serious it is, but looking at the definition of that exception, seems to be a CancellationException that should've probably been swallowed.

private class SuspendAppShutdown : CancellationException("SuspendApp shutting down.")

Behaviour seems consistent and has survived refactoring (last time I introduced suspendapp-ktor). But if you want, I can come up with a minimal example.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions