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

Commit 68f1471

Browse files
committed
fix: handle uninitialized response in RespondingNettyPacket
- Modified `response` to use lazy initialization with `CompletableDeferred` for proper memory handling. - Ensure exception completion if response is accessed after connection garbage collection.
1 parent ee7f6cc commit 68f1471

File tree

1 file changed

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

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ abstract class RespondingNettyPacket<P : ResponseNettyPacket> : NettyPacket() {
3838
* A deferred response object for awaiting the associated response.
3939
*/
4040
@InternalApi
41-
val response = CompletableDeferred<P>()
41+
val response by lazy { CompletableDeferred<P>() }
4242

4343
/**
4444
* The connection through which the response will be sent.
@@ -120,6 +120,11 @@ abstract class RespondingNettyPacket<P : ResponseNettyPacket> : NettyPacket() {
120120
if (responseConnection == null) {
121121
log.atWarning()
122122
.log("Cannot respond to packet ${this::class.simpleName} with session ID $uniqueSessionId: original connection has been garbage collected")
123+
124+
if ((::response.getDelegate() as Lazy<*>).isInitialized()) {
125+
response.completeExceptionally(IllegalStateException("Original connection has been garbage collected"))
126+
}
127+
123128
return
124129
}
125130

0 commit comments

Comments
 (0)