File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
LavalinkServer/src/main/java/lavalink/server/io Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 1+ package lavalink.server.io
2+
3+ import org.springframework.web.socket.CloseStatus
4+
5+ class ShutdownHandler (private val socketServer : SocketServer ) : Thread(" lavalink-shutdown-handler" ) {
6+ init {
7+ isDaemon = false // we want this thread to block shutdown until it has finished running
8+ }
9+
10+ override fun run () {
11+ socketServer.contexts.forEach {
12+ // don't care about exceptions here, the JVM's shutting down anyway.
13+ it.runCatching { closeWebSocket(CloseStatus .GOING_AWAY .code) }
14+ }
15+ }
16+ }
Original file line number Diff line number Diff line change @@ -56,6 +56,10 @@ final class SocketServer(
5656 private val statsCollector = StatsCollector (this )
5757 private val charPool = (' a' .. ' z' ) + (' 0' .. ' 9' )
5858
59+ init {
60+ Runtime .getRuntime().addShutdownHook(ShutdownHandler (this ))
61+ }
62+
5963 companion object {
6064 private val log = LoggerFactory .getLogger(SocketServer ::class .java)
6165
You can’t perform that action at this time.
0 commit comments