Created by: spmason
The docs for ofInputStream say:
To ensure that all resources associated with the corresponding exchange are properly released the caller must ensure to either read all lines until the stream is exhausted, or call BaseStream.close() if it is unable or unwilling to do so. Calling close before exhausting the stream may cause the underlying HTTP connection to be closed and prevent it from being reused for subsequent operations.
When ObjectMapper.readValue is called with an InputStream it implicitly closes it, but when the library is not expecting a return type it's not passing the InputStream to Jackson, so the stream needs to be manually drained and closed as per the docs
Failure to do this leads to a leak of HttpClient socket handles, and ultimately the exception java.net.BindException: Cannot assign requested address
when trying to make API calls
It's difficult to write an automated test for this situation. I've tested it on my own project by making the template changes locally and observing that the number of open file descriptors held by my service stopped increasing the more api calls were made, and that the BindException
was no longer triggered after a few hours of operation
PR checklist
-
Read the contribution guidelines. -
Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community. -
Run the following to build the project and update samples: ./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
./bin/generate-samples.sh bin/configs/java*
. For Windows users, please run the script in Git BASH. -
File the PR against the correct branch: master
(5.3.0),6.0.x
-
If your PR is targeting a particular programming language, mention the technical committee members, so they are more likely to review the pull request: @bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @nmuesch