Discord Integration Forge

Discord Integration Forge

935k Downloads

[BUG] getWebhook blocks server thread for many seconds

sfPlayer1 opened this issue ยท 1 comments

commented

dcintegration-1.3.4-1.16 has been observed blocking the server thread for over 10 seconds in de.erdbeerbaerlp.dcintegration.Discord.getWebhook() / net.dv8tion.jda.api.requests.RestAction.complete(). This was presumably due to its blocking getWebhook implementation paired with Discord having a period of particularly slow API responses. Another occurrence blocked the server for 36 seconds, but I didn't capture a trace for it. These interactions should never block the server thread.

From what I can tell at a quick glance, JDA offers RestAction.submit instead of .complete to obtain a CompletableFuture for the webhook. CompletableFuture.thenAccept and similar methods can then be used to execute the desired action (.send+.close) when the original operation has completed - without waiting/blocking the caller. You want to finish the CompletableFuture chain with .whenComplete or .exceptionally to print any exceptions, otherwise they get lost.

VisualVM compatible nps file showing the issue:
http://files.player.to/tmp/spike-10486-16338923416.nps
The file shows a capture for a single tick only. Server thread is waiting 10.4s on the completion of a JDA future, which presumably corresponds to the request execution on JDA RateLimit-Worker 1.

commented

This is probably the number one forgecraft killer right now. It seems this happens regularly, and causes many second lockups of the serverthread, sometimes resulting in watchdog kills :(