-
Notifications
You must be signed in to change notification settings - Fork 484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Close HTTP client owned by MinioClient #1546
Close HTTP client owned by MinioClient #1546
Conversation
@@ -145,7 +146,8 @@ protected S3Base( | |||
boolean useVirtualStyle, | |||
String region, | |||
Provider provider, | |||
OkHttpClient httpClient) { | |||
OkHttpClient httpClient, | |||
boolean closeHttpClient) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks backward compatibility.
You would need to create another constructor and have this closeHttpClient
argument and call the newly added constructor in this constructor.
Finally deprecate this constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, fixed!
@@ -193,6 +197,7 @@ protected S3Base(S3Base client) { | |||
this.region = client.region; | |||
this.provider = client.provider; | |||
this.httpClient = client.httpClient; | |||
this.closeHttpClient = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.closeHttpClient = false; | |
this.closeHttpClient = client.closeHttpClient; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That depends on the purpose of this "copy" constructor, i.e. what semantics we want,
If the caller may use both instances of S3Base, only one should close the HTTP client (and then the other is not usable anymore).
If the caller is supposed to use only the new instance of S3Base, yes, we should copy the flag.
For now, I will copy the flag.
@balamurugana thank you for your review! |
88bf15c
to
0ed5c57
Compare
MinioClient builder and MinioAsyncClient builder allocate a new OkHttpClient instance. OkHttpClient manages internal resources such as dispatcher thread pool for executing HTTP requests and should be closed to dispose of these resources.
0ed5c57
to
cc4d1b9
Compare
Please fix the CI failure |
I see this failure on the CI
I am able to reproduce the failure locally with (following the CI script minio-java/.github/workflows/gradle.yml Lines 34 to 44 in fcbfa54
./gradlew clean build &&
DEV_VERSION="$(./gradlew properties | awk '/^version:/ { print $2 }')" &&
javac -cp api/build/libs/minio-${DEV_VERSION}-all.jar functional/TestUserAgent.java &&
java -Dversion=${DEV_VERSION} -cp api/build/libs/minio-${DEV_VERSION}-all.jar:functional TestUserAgent however, I think I am doing something wrong still, as the above fails also when I run it on master. |
@findepi diff --git a/functional/TestUserAgent.java b/functional/TestUserAgent.java
index fca96cfb..51180f99 100644
--- a/functional/TestUserAgent.java
+++ b/functional/TestUserAgent.java
@@ -23,7 +23,7 @@ import java.util.Scanner;
public class TestUserAgent {
public static void main(String[] args) throws Exception {
- MinioClient client = MinioClient.builder().endpoint("http://example.org").build();
+ MinioClient client = MinioClient.builder().endpoint("http://httpbin.org").build();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
client.traceOn(baos);
client.bucketExists(BucketExistsArgs.builder().bucket("any-bucket-name-works").build()); |
@balamurugana done! |
@balamurugana thanks for review! |
MinioClient builder and MinioAsyncClient builder allocate a new OkHttpClient instance. OkHttpClient manages internal resources such as dispatcher thread pool for executing HTTP requests and should be closed to dispose of these resources.