You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a subscriber sends a cancellation signal upstream, connections might not get closed. This produces connections leaks which lead to non-responding applications in the long term.
Table schema
Input Code
create extension if not exists "uuid-ossp";
createtableif not exists test_entity
(
id uuid default public.uuid_generate_v4(),
name textnot null,
primary key (id)
);
Steps to reproduce
Input Code
privateval logger =LoggerFactory.getLogger("StressTest")
funmain(args:Array<String>) {
runStressTest()
}
privatefunrunStressTest() {
val pool = connectionPool()
val client =DatabaseClient.create(pool)
val threads = (1..5).map { runStressTestRequestThread(it, client) }
threads.forEach { it.join() }
Thread.sleep(20_000) // connection should be evicted after 10 secondsassert(pool.metrics.get().allocatedSize() ==0) // this fails
}
privatefunrunStressTestRequestThread(num:Int, databaseClient:DatabaseClient): Thread=
thread(name ="stress-test-$num") {
for (i in (1..1_000)) {
runCatching {
databaseClient.sql("select id, name from test_entity")
.then()
.timeout(Duration.ofMillis(15)) // cancel before answer
.block()
}.onFailure {
logger.debug(it.message, it)
}
}
logger.info("done")
}
privatefunconnectionPool(): ConnectionPool=ConnectionPoolConfiguration
.builder(connectionFactory())
.maxSize(1)
.initialSize(0)
.maxIdleTime(Duration.ofSeconds(1))
.maxLifeTime(Duration.ofSeconds(1))
.backgroundEvictionInterval(Duration.ofSeconds(1))
.build()
.let { ConnectionPool(it) }
privatefunconnectionFactory(): ConnectionFactory=ConnectionFactories.get(
ConnectionFactoryOptions.parse("r2dbc:postgresql://localhost:5432/test?schema=test")
.mutate()
.option(ConnectionFactoryOptions.USER, "postgres")
.option(ConnectionFactoryOptions.PASSWORD, "pass")
.build()
)
I also created a demo where this occurs in combination with a netty based spring webflux setup here, that's how i found out about this. This example uses spring boot r2dbc. https://github.com/stefannegele/connection-leak-demo
Expected behavior/code
Connection does not leak.
The text was updated successfully, but these errors were encountered:
stefannegele
changed the title
Connections leak on pubisher cancellation
Connections leak on subscription cancellation
Oct 28, 2021
Sorry for the duplicate. Did not catch the other issue, because it was raised while i was still investigating.
I will now wait for a new release of the pool and run my tests with the new version again. Thanks a lot!
Bug Report
Versions
Current Behavior
When a subscriber sends a cancellation signal upstream, connections might not get closed. This produces connections leaks which lead to non-responding applications in the long term.
Table schema
Input Code
Steps to reproduce
Input Code
I also created a demo where this occurs in combination with a netty based spring webflux setup here, that's how i found out about this. This example uses spring boot r2dbc.
https://github.com/stefannegele/connection-leak-demo
Expected behavior/code
Connection does not leak.
The text was updated successfully, but these errors were encountered: