Skip to content

Commit

Permalink
KTOR-6178 MicrometerMetricsConfig default registry leaks coroutine (#…
Browse files Browse the repository at this point in the history
…3721)

(cherry picked from commit b2bf9cf)
  • Loading branch information
rsinukov authored and e5l committed Aug 30, 2023
1 parent e56b8bd commit 3c7e8c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public class MicrometerMetricsConfig {
* @see [MicrometerMetrics]
*/
public var registry: MeterRegistry = LoggingMeterRegistry()
set(value) {
field.close()
field = value
}

/**
* Specifies if requests for non-existent routes should
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import io.micrometer.core.instrument.binder.*
import io.micrometer.core.instrument.binder.jvm.*
import io.micrometer.core.instrument.binder.system.*
import io.micrometer.core.instrument.distribution.*
import io.micrometer.core.instrument.logging.*
import io.micrometer.core.instrument.simple.*
import kotlin.reflect.*
import kotlin.test.*
Expand Down Expand Up @@ -399,6 +400,27 @@ class MicrometerMetricsTests {
assertEquals("OK", response.bodyAsText())
}

@Test
fun `test closes previous registry`(): Unit = testApplication {
var closed = false
val metrics = object : LoggingMeterRegistry() {
override fun close() {
super.close()
closed = true
}
}

application {
install(MicrometerMetrics) {
registry = metrics
registry = LoggingMeterRegistry()
}
}

startApplication()
assertTrue(closed)
}

private fun TestApplicationEngine.metersAreRegistered(
meterBinder: KClass<out MeterBinder>,
vararg meterNames: String
Expand Down

0 comments on commit 3c7e8c0

Please sign in to comment.