Skip to content

Commit

Permalink
fix(adam): fix vertx socket factory crash during shutdown
Browse files Browse the repository at this point in the history
during shutdown currently close of the socket factory might initialise the vertx object. this in turn adds a new shutdown hook which is impossible during the shutdown.
Check if the vertx has been initialised before accessing the property
  • Loading branch information
Malinskiy committed Apr 21, 2022
1 parent 652f039 commit 50836dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ import io.vertx.core.net.NetClientOptions
import io.vertx.core.net.SocketAddress
import io.vertx.kotlin.coroutines.await
import java.net.InetSocketAddress
import java.util.concurrent.atomic.AtomicBoolean

class VertxSocketFactory(
private val connectTimeout: Long = 10_000,
private val idleTimeout: Long = 30_000
) : SocketFactory {
private val vertx by lazy { Vertx.vertx() }
private val vertx by lazy {
Vertx.vertx().also { initialized.set(true) }
}
private val initialized = AtomicBoolean(false)

override suspend fun tcp(socketAddress: InetSocketAddress, connectTimeout: Long?, idleTimeout: Long?): Socket {
val vertxSocket = VertxSocket(SocketAddress.inetSocketAddress(socketAddress), NetClientOptions().apply {
Expand All @@ -41,7 +45,9 @@ class VertxSocketFactory(
}

override fun close() {
vertx.close()
if (initialized.get()) {
vertx.close()
}
}

private fun Long.toTimeoutInt(): Int {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object Versions {
val adam = System.getenv("GIT_TAG_NAME") ?: "0.4.3"
val adam = System.getenv("GIT_TAG_NAME") ?: "0.4.5"
val kotlin = "1.6.10"
val coroutines = "1.6.0"
val coroutinesDebug = coroutines
Expand Down

0 comments on commit 50836dc

Please sign in to comment.