-
-
Notifications
You must be signed in to change notification settings - Fork 677
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shutdown hook to close clients properly
- Loading branch information
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
LavalinkServer/src/main/java/lavalink/server/io/ShutdownHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package lavalink.server.io | ||
|
||
import org.springframework.web.socket.CloseStatus | ||
|
||
class ShutdownHandler(private val socketServer: SocketServer) : Thread("lavalink-shutdown-handler") { | ||
init { | ||
isDaemon = false // we want this thread to block shutdown until it has finished running | ||
} | ||
|
||
override fun run() { | ||
socketServer.contexts.forEach { | ||
// don't care about exceptions here, the JVM's shutting down anyway. | ||
it.runCatching { closeWebSocket(CloseStatus.GOING_AWAY.code) } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters