mirror of
https://github.com/System-End/Discord-MC-Chat.git
synced 2026-04-19 16:28:23 +00:00
Fix potential thread leak on init failures
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
39f4189a9a
commit
5d34d8544d
1 changed files with 6 additions and 1 deletions
|
|
@ -72,6 +72,7 @@ public class DiscordManager {
|
|||
try {
|
||||
// Blocks until JDA is ready
|
||||
CompletableFuture<Void> readyFuture = CompletableFuture.runAsync(() -> {
|
||||
ExecutorService eventExecutor = Executors.newSingleThreadExecutor(ExecutorServiceUtils.newThreadFactory("DMCC-DiscordEvent"));
|
||||
try {
|
||||
jda = JDABuilder.createDefault(token)
|
||||
.enableIntents(
|
||||
|
|
@ -80,13 +81,17 @@ public class DiscordManager {
|
|||
GatewayIntent.GUILD_MESSAGE_REACTIONS
|
||||
)
|
||||
.setMemberCachePolicy(MemberCachePolicy.ALL)
|
||||
.setEventPool(Executors.newSingleThreadExecutor(ExecutorServiceUtils.newThreadFactory("DMCC-DiscordEvent")), true)
|
||||
.setEventPool(eventExecutor, true)
|
||||
.addEventListeners(new DiscordEventHandler())
|
||||
.build();
|
||||
|
||||
jda.awaitReady();
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.error(I18nManager.getDmccTranslation("discord.manager.init_interrupted"), e);
|
||||
} catch (RuntimeException e) {
|
||||
// If build() fails before JDA takes ownership of the event executor, shut it down to avoid leaks
|
||||
eventExecutor.shutdownNow();
|
||||
throw e;
|
||||
}
|
||||
}, executor);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue