Skip to content

Commit

Permalink
Merge pull request #80 from Malinskiy/fix/vertx-shutdown-behaviour
Browse files Browse the repository at this point in the history
fix(adam): fix vertx socket factory crash during shutdown
  • Loading branch information
Malinskiy authored Apr 21, 2022
2 parents 652f039 + 50836dc commit 0172564
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 0172564

Please sign in to comment.