Skip to content

Commit 5067efe

Browse files
committed
Use the "connection reset" error code from Netty instead of hard-coding it and also catch Java NIO SocketException for developing on other OSs such as macOS and Windows
Tested with the `tfb` command on both macOS and Linux.
1 parent ffa242c commit 5067efe

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

frameworks/Kotlin/vertx-web-kotlinx/src/main/kotlin/MainVerticle.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import io.netty.channel.unix.Errors
12
import io.netty.channel.unix.Errors.NativeIoException
23
import io.vertx.core.MultiMap
34
import io.vertx.core.buffer.Buffer
@@ -30,6 +31,7 @@ import kotlinx.serialization.Serializable
3031
import kotlinx.serialization.SerializationStrategy
3132
import kotlinx.serialization.json.Json
3233
import kotlinx.serialization.json.io.encodeToSink
34+
import java.net.SocketException
3335
import kotlin.time.Clock
3436

3537
class MainVerticle(val hasDb: Boolean) : CoroutineVerticle(), CoroutineRouterSupport {
@@ -84,12 +86,8 @@ class MainVerticle(val hasDb: Boolean) : CoroutineVerticle(), CoroutineRouterSup
8486
.requestHandler(Router.router(vertx).apply { routes() })
8587
.exceptionHandler {
8688
// wrk resets the connections when benchmarking is finished.
87-
if (
88-
// for epoll
89-
/*(it is NativeIoException && it.message == "recvAddress(..) failed: Connection reset by peer")
90-
|| (it is SocketException && it.message == "Connection reset")*/
91-
// for io_uring
92-
it is NativeIoException && it.expectedErr() == -104
89+
if ((/* for native transport */it is NativeIoException && it.expectedErr() == Errors.ERRNO_ECONNRESET_NEGATIVE) ||
90+
(/* for Java NIO */ it is SocketException && it.message == "Connection reset")
9391
)
9492
return@exceptionHandler
9593

0 commit comments

Comments
 (0)