MinnDevelopment / discord-webhooks

Provides easy to use bindings for the Discord Webhook API
Apache License 2.0
180 stars 34 forks source link

Thread limit reached. #61

Closed EinBexiii closed 2 years ago

EinBexiii commented 2 years ago

It seems like this libary creates for each Webhook a thread:

https://github.com/MinnDevelopment/discord-webhooks/blob/c6bf011e313baae33dad8fa8d763d9543d84dad0/src/main/java/club/minnced/discord/webhook/util/ThreadPools.java#L25

This causes the thread limit to be reached when e.g. several webhooks are sent per minute. "java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached"

I profiled it with YourKit, the threads will not be shutdowned.

Solution: Shutdown the thread or use a Pool of threads. Or make possible to use own thread pool.

MinnDevelopment commented 2 years ago

You should re-use the webhook clients to allow it to share the threads for each message. If you are done with a webhook client, close it with WebhookClient#close. This is explained in the README.

EinBexiii commented 2 years ago

You should re-use the webhook clients to allow it to share the threads for each message. If you are done with a webhook client, close it with WebhookClient#close. This is explained in the README.

Actually, I made a mistake at one point that the WebhookClient was never closed.