Resource leak by not closing the client
See original GitHub issueThe HTTP client is not explicitly closed, leading to possible leaks. The JAX-RS ClientBuilder
is dynamically resolved, which in my case uses RestEasy instead of Jersey. In that case it uses a finalizer
to log a warning that the client wasn’t closed, which is a requirement of the API. It would also be nice if these were pooled.
These issues makes it a little uncomfortable to use this SDK in a production with a reasonable email volume.
* Client is the main entry point to the fluent API used to build and execute client
* requests in order to consume responses returned.
* <p/>
* Clients are heavy-weight objects that manage the client-side communication
* infrastructure. Initialization as well as disposal of a {@code Client} instance
* may be a rather expensive operation. It is therefore advised to construct only
* a small number of {@code Client} instances in the application. Client instances
* must be {@link #close() properly closed} before being disposed to avoid leaking
* resources.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Potential resource leak: 'client' may not be closed at this location
I'm using HttpClient , but in Eclipse I'm getting warning "Potential resource leak".
Read more >Closing Sockets and Avoiding Resource Leaks - Documentation
Resource leaks, like memory leaks, can lead to subtle bugs, as shown in the ... The destructor for RWSocket, however, does not close...
Read more >Resource leak | Amazon CodeGuru Reviewer, Detector Library
Allocated resources are not released properly. This can slow down or crash your system. They must be closed along all paths to prevent...
Read more >Finding and fixing memory leaks in Go - DEV Community
But, what happens if you don't Close the client when you should? You get a memory leak. The underlying connections never get cleaned...
Read more >How to Detect Memory Leaks in Java: Causes, Types, & Tools
If memory leaks are not handled, your application can eventually run out of memory and terminate. Learn what causes memory leaks in Java...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kopax, I was using simpleJavaMail, which is a really excellent library. However, the SMTP endpoint is very flaky at scale and requires retries. Mailgun’s support wasn’t helpful except acknowledging that they do some nasty things in their load balancer to cycle IPs for defensive reasons. They said the HTTP api was faster and more robust, so I had to port over.
I wrote an
Email
class similar to @sargue’sMailBuilder
class to aggregate the contents into a multipart. This goes to a Retrofit interface, which is backed by a shared OkHttp client. Not much work thanks to this library and the api docs to clarify their endpoint.mailgun.zip
My requirements are the same and not bulk mail, but it amounts to around 800k/month. This is for example a company sending an invoice to their customer.
I did not include the code using this client, which adds those to the
Email
class, invokes theMailgun.send
method, and handles all of the metrics / retrials / etc. You would use this as,Anyone is welcome to formalize into a reusable client, like @sargue’s nice library. It was not much work on my part, Retrofit does all the heavy lifting and this is just an example of how quickly one can bootstrap a usage.