improve addShutdownHook KDoc#5548
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (3)
📝 WalkthroughWalkthroughDocumentation was updated for shutdown-hook registration across common, JVM, Native, and Web sources. The revised comments describe registration timing, platform-specific listener behavior, execution order, and normal-stop versus termination-signal behavior. No logic or public signatures changed. ChangesShutdown hook documentation
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
ktor-server/ktor-server-core/common/src/io/ktor/server/engine/ShutdownHook.kt (1)
30-31: Consider refining "while the application is running" for precision.The phrase "while the application is running" is slightly imprecise. Based on the implementation (line 38), the hook is registered when the
ApplicationStartingevent fires, which occurs during the startup phase rather than while the application is running.Consider:
-The hook is only registered while the application is running. If the application has already stopped, +The hook is registered when the application starts. If the application has already stopped,This minor change aligns the wording more precisely with the
ApplicationStartingevent subscription. However, the current phrasing is understandable in context.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ktor-server/ktor-server-core/common/src/io/ktor/server/engine/ShutdownHook.kt` around lines 30 - 31, The comment text "while the application is running" is imprecise; update the wording in ShutdownHook.kt to state that the hook is registered during startup when the ApplicationStarting event fires (rather than "while running"), and ensure the description still notes that if the application has already stopped no hook is registered and stop will never be called; reference the ApplicationStarting event and the stop method to make the behavior explicit.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@ktor-server/ktor-server-core/common/src/io/ktor/server/engine/ShutdownHook.kt`:
- Around line 27-28: ShutdownHookNative.kt currently overwrites previous hooks
by assigning shutdownHook.value = ..., so addShutdownHook() on Native only keeps
the last hook; change the Native implementation to accumulate independent hooks
(e.g., store a thread-safe collection or an AtomicReference<List<() -> Unit>>
and append new callbacks, or chain the new hook to call the existing hook) so
every call to addShutdownHook() registers an independent callback and all are
executed on shutdown; additionally either implement true deregistration
semantics on Native/Web to match JVM (so EmbeddedServer.stop can remove its
hook) or update the documentation to clearly state that only the JVM platform
removes the actual shutdown hook while Native/Web use a guard to prevent
re-execution (and adjust the deregistration wording accordingly).
---
Nitpick comments:
In
`@ktor-server/ktor-server-core/common/src/io/ktor/server/engine/ShutdownHook.kt`:
- Around line 30-31: The comment text "while the application is running" is
imprecise; update the wording in ShutdownHook.kt to state that the hook is
registered during startup when the ApplicationStarting event fires (rather than
"while running"), and ensure the description still notes that if the application
has already stopped no hook is registered and stop will never be called;
reference the ApplicationStarting event and the stop method to make the behavior
explicit.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b97ae795-0f02-4e63-86b1-0943b38b0980
📒 Files selected for processing (1)
ktor-server/ktor-server-core/common/src/io/ktor/server/engine/ShutdownHook.kt
| * (JVM shutdown hook on JVM, POSIX signal on Native, process event on JS). | ||
| * Should be called **before** starting the server. | ||
| * | ||
| * Multiple shutdown hooks can be registered by calling this function more than once — |
There was a problem hiding this comment.
What order will the callbacks be executed?
| * each call adds an independent hook. For example, different application modules can each | ||
| * register their own cleanup logic. | ||
| * | ||
| * The [stop] block is **not** a listener for lifecycle events — it is the **cause** of the |
There was a problem hiding this comment.
What is the cause of shutdown sequence?
| * [io.ktor.server.application.ApplicationStopping], and | ||
| * [io.ktor.server.application.ApplicationStopped] in that order. | ||
| * | ||
| * If the application is stopped normally (e.g., by calling [EmbeddedServer.stop] directly), |
There was a problem hiding this comment.
Is it necessary to include this in the KDoc?
fc08da4 to
756fec6
Compare
Subsystem
Server Docs
Motivation
KTOR-9504 Improve KDoc for EmbeddedServer.addShutdownHook