[Bug] fix JDA hangs ~10 min on server stop #129
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checks
Description
Hi @Xujiayao, hope you're doing well.
Because of the activation of the udpateTopic feature and in some case, the JVM is kept running several minutes after the server has stopped. There's absolutely no log from the mod when the problem occurs.
It seems to be cause by the high rate limit on the discord endpoint api used to update a channel's topic and the fact that MCDC wait for the update to be complete before shutting down the JDA instance. (after quick research, same problem encountered on some other discord integration mod/plugin)
In this fix, the topic update is queued and the mod does not wait anymore for the completion of the future. I also explicitly terminated the HTTPClient instance used by JDA to be sure that, in any case, it will not kept the JVM running after the shutdown. (JDA Doc)
I think there's not over way to avoid this issue due to the discord endpoint rate limit. We could probably add a new config key to let the user free to decide if he wants the server to wait the topic update before shutting down or not.
I hope i didn't miss anything... Feel free to ask if any change need :)