Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract class RespondingNettyPacket<P : ResponseNettyPacket> : NettyPacket() {
* A deferred response object for awaiting the associated response.
*/
@InternalApi
val response = CompletableDeferred<P>()
val response by lazy { CompletableDeferred<P>() }

/**
* The connection through which the response will be sent.
Expand Down Expand Up @@ -120,6 +120,11 @@ abstract class RespondingNettyPacket<P : ResponseNettyPacket> : NettyPacket() {
if (responseConnection == null) {
log.atWarning()
.log("Cannot respond to packet ${this::class.simpleName} with session ID $uniqueSessionId: original connection has been garbage collected")

if ((::response.getDelegate() as Lazy<*>).isInitialized()) {
response.completeExceptionally(IllegalStateException("Original connection has been garbage collected"))
}

return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ interface PersistentPlayerDataContainerView {
*/
const val MAX_NESTING_DEPTH = 512

/**
* Ensures that the nesting depth does not exceed the maximum allowed limit.
*
* This function validates that the provided depth is within acceptable bounds,
* preventing memory exhaustion from extremely deep nested structures.
*
* @param depth The current nesting depth to validate.
* @param exceptionFactory A factory function that creates the exception to throw
* when the depth exceeds the limit. Defaults to [IllegalStateException].
* @throws Throwable When the depth exceeds [MAX_NESTING_DEPTH]. The specific exception
* type is determined by the [exceptionFactory] parameter.
*/
inline fun ensureValidNestingDepth(
depth: Int,
exceptionFactory: (message: String) -> Throwable = ::IllegalStateException
Expand Down
Loading