Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KHealth 2+ stores all ApplicationCall objects #2

Closed
glebignatieff opened this issue Jul 26, 2022 · 1 comment
Closed

KHealth 2+ stores all ApplicationCall objects #2

glebignatieff opened this issue Jul 26, 2022 · 1 comment

Comments

@glebignatieff
Copy link

glebignatieff commented Jul 26, 2022

Hi!

There seems to be a bug since version 2.0.0, leading to KHealth storing all ApplicationCall objects and calling them on each /health or /ready. As I understand, interceptor should create a route handler for /health and /ready only once, therefore right now it behaves weirdly.

It happens because there's already a call argument in the top function, which shadows the one in get handler:

fun interceptor(call: ApplicationCall) {
val routing: Routing.() -> Unit = {
val routing: Route.() -> Unit = {
if (config.readyCheckEnabled) route(config.readyCheckPath) {
get {
val (status, responseBody) = processChecks(
checkLinkedList = config.readyChecks,
passingStatusCode = config.successfulCheckStatusCode,
failingStatusCode = config.unsuccessfulCheckStatusCode
)
call.respondText(responseBody, ContentType.Application.Json, status)

Steps to reproduce

  1. Generate Ktor project with Routing and CallLogging.
  2. Add khealth package to build.gradle.kts.
  3. Add install(KHealth) to embeddedServer builder in Application.kt.
  4. Run the app.
  5. Get a few / and then /health.

Expected behavior

2 / and one /health:

2022-07-26 11:20:15.307 [eventLoopGroupProxy-4-3] INFO  ktor.application - 200 OK: GET - /
2022-07-26 11:20:15.308 [eventLoopGroupProxy-4-3] INFO  ktor.application - 200 OK: GET - /
2022-07-26 11:20:15.309 [eventLoopGroupProxy-4-3] INFO  ktor.application - 200 OK: GET - /health

Actual behavior

Calling /health gives two more / logs and then /health.

2022-07-26 11:20:12.121 [eventLoopGroupProxy-4-2] INFO  ktor.application - 200 OK: GET - /
2022-07-26 11:20:12.121 [eventLoopGroupProxy-4-1] INFO  ktor.application - 200 OK: GET - /
2022-07-26 11:20:15.307 [eventLoopGroupProxy-4-3] INFO  ktor.application - 200 OK: GET - /
2022-07-26 11:20:15.308 [eventLoopGroupProxy-4-3] INFO  ktor.application - 200 OK: GET - /
2022-07-26 11:20:15.309 [eventLoopGroupProxy-4-3] INFO  ktor.application - 200 OK: GET - /health

As you can see, 2 previous / calls have been stored and with each /health get handler is called with all these calls.

@HaydenMeloche
Copy link
Owner

HaydenMeloche commented Jul 27, 2022

Hi @glebignatieff
thanks for the detailed bug report! I published a fix for this under 2.1.1 in commit 7c7b239

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants