Skip to content

Commit d9be9eb

Browse files
committed
fix channel closed exception
1 parent 79b93be commit d9be9eb

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Mon Sep 02 03:41:15 CEST 2024
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

src/main/kotlin/net/ccbluex/netty/http/websocket/WebSocketController.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import kotlinx.coroutines.joinAll
3232
import kotlinx.coroutines.launch
3333
import net.ccbluex.netty.http.HttpServer.Companion.logger
3434
import net.ccbluex.netty.http.coroutines.syncSuspend
35+
import java.nio.channels.ClosedChannelException
3536
import java.nio.charset.Charset
3637
import java.util.concurrent.CopyOnWriteArraySet
3738
import java.util.function.BiConsumer
@@ -78,18 +79,16 @@ class WebSocketController(
7879

7980
activeContexts.map { handlerContext ->
8081
launch {
81-
if (handlerContext.channel().isActive) {
82-
try {
83-
handlerContext.channel()
84-
.writeAndFlush(frame.retainedDuplicate())
85-
.syncSuspend()
86-
} catch (e: Throwable) {
87-
onFailure?.accept(handlerContext, e)
88-
}
89-
} else {
82+
try {
83+
handlerContext.channel()
84+
.writeAndFlush(frame.retainedDuplicate())
85+
.syncSuspend()
86+
} catch (_: ClosedChannelException) {
9087
// Channel is not active, close and remove it
9188
handlerContext.close().syncSuspend()
9289
removeContext(handlerContext)
90+
} catch (e: Throwable) {
91+
onFailure?.accept(handlerContext, e)
9392
}
9493
}
9594
}.joinAll()

0 commit comments

Comments
 (0)