Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit d951ff9

Browse files
committed
feat: enhance timeout handling in fireAndAwaitOrThrow method with logging
1 parent abb1359 commit d951ff9

File tree

1 file changed

+18
-3
lines changed
  • surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/netty/packet

1 file changed

+18
-3
lines changed

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/netty/packet/RespondingNettyPacket.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import dev.slne.surf.cloud.api.common.netty.network.Connection
44
import dev.slne.surf.cloud.api.common.netty.protocol.buffer.readUuid
55
import dev.slne.surf.cloud.api.common.netty.protocol.buffer.writeUuid
66
import dev.slne.surf.cloud.api.common.util.annotation.InternalApi
7+
import dev.slne.surf.surfapi.core.api.util.logger
78
import io.netty.buffer.ByteBuf
89
import kotlinx.coroutines.CompletableDeferred
10+
import kotlinx.coroutines.TimeoutCancellationException
911
import kotlinx.coroutines.withTimeout
1012
import kotlinx.coroutines.withTimeoutOrNull
1113
import java.util.*
@@ -75,9 +77,18 @@ abstract class RespondingNettyPacket<P : ResponseNettyPacket> : NettyPacket() {
7577
suspend fun fireAndAwaitOrThrow(
7678
connection: Connection,
7779
timeout: Duration = DEFAULT_TIMEOUT
78-
): P = withTimeout(timeout) {
79-
connection.send(this@RespondingNettyPacket)
80-
response.await()
80+
): P {
81+
try {
82+
return withTimeout(timeout) {
83+
connection.send(this@RespondingNettyPacket)
84+
response.await()
85+
}
86+
} catch (e: TimeoutCancellationException) {
87+
log.atWarning()
88+
.withCause(e.createCopy())
89+
.log("Timeout while waiting for response to packet ${this::class.simpleName} with session ID $uniqueSessionId")
90+
throw e
91+
}
8192
}
8293

8394
/**
@@ -129,4 +140,8 @@ abstract class RespondingNettyPacket<P : ResponseNettyPacket> : NettyPacket() {
129140
@InternalApi
130141
fun getUniqueSessionIdOrCreate(): UUID =
131142
uniqueSessionId ?: UUID.randomUUID().also { uniqueSessionId = it }
143+
144+
companion object {
145+
private val log = logger()
146+
}
132147
}

0 commit comments

Comments
 (0)