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
Fix connections leaking on high load. #290
Fix connections leaking on high load. #290
Conversation
sbmpost
commented
Apr 28, 2022
•
edited
edited
- Moves the responsibility of connection create timeout completely to the connection.
- By doing so, allows us to close the underlying Netty Channel if the creation times out.
...async/src/main/java/com/github/jasync/sql/db/postgresql/codec/PostgreSQLConnectionHandler.kt
Outdated
Show resolved
Hide resolved
...async/src/main/java/com/github/jasync/sql/db/postgresql/codec/PostgreSQLConnectionHandler.kt
Outdated
Show resolved
Hide resolved
798288a
to
814c385
Compare
@oshai |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
@@ -50,6 +51,7 @@ data class Configuration @JvmOverloads constructor( | |||
val maximumMessageSize: Int = 16777216, | |||
val allocator: ByteBufAllocator = PooledByteBufAllocator.DEFAULT, | |||
val connectionTimeout: Int = 5000, | |||
val createTimeout: Duration = Duration.ofMillis(5000), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is exactly as connectionTimeout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, will fix this
delegate.onError(message) | ||
|
||
override fun onOk(message: OkMessage) { | ||
Thread.sleep(onOkSlowdownInMillis) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to make the network connection, but to simulate a significant delay in the response of MySQL server so that the create/connectionTimeout kicks in. As far as I can tell, the Ok message is similar to the PostgreSQL ReadyForQuery message (see issue #288)
class MySQLSlowConnectionDelegate( | ||
private val delegate: MySQLHandlerDelegate, | ||
private val onOkSlowdownInMillis: Long | ||
) : MySQLHandlerDelegate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kotlin has a delegate feature, maybe you can use that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That certainly removed a lot of boilerplate code, thanks!
@@ -337,17 +336,6 @@ private class ObjectPoolActor<T : PooledObject>( | |||
} | |||
} | |||
|
|||
private fun checkItemsInCreationForTimeout() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep that as a safety mechanism, maybe with a bigger threshold like createTimeout * 2 (or + 20 seconds)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good idea to keep things backwards compatible. I have restored it.
@oshai |
@oshai can we consider to merge this? |
I am not available in the next two weeks so will complete the review once back. |
The CI fails on formatting (also failed on using old kotlin version without last ,). I will fix it later today or you can do that - I want to make sure CI pass before merging. |
The change cause some tests fail. Maybe the timeout is misconfigured or there is another issue. I would appreciate if you can take a look. |
@oshai |
@oshai I had to fix the same thing for postgresql. I can't restart the test myself, but I think all should be well now. |
ok thanks! I will merge once all tests pass. |
Thanks for the PR! I will create a new version soon. |
releasing it now on v2.0.8 |
Moves the responsibility of connection create timeout completely to the connection. By doing so, allows us to close the underlying Netty Channel if the creation times out. Also: * Lower connectionTimeout in the unit tests * Fix unit tests