Thread blocking cause by the default setting
JokerForCode opened this issue · 2 comments
JokerForCode commented
Only set up the variable "requestTimeoutEnabled" and "requestTimeout" both of “ClientBuilderConfiguration”,the ossClient will be block until time-out,and throw timeoutException.However, the “requestTimeoutEnabled” is set up "false", or the "requestTimeout" is set up 'null',the request of OSS Http will occur timeout,but in the code,it never throw exception,the thread will be block until dead.
the right code to catch exception:
ClientBuilderConfiguration configuration = new ClientBuilderConfiguration();
configuration.setRequestTimeoutEnabled(Boolean.TRUE);
configuration.setRequestTimeout(300_000);
OSS aliyunOssClient = new OSSClientBuilder().build(xxx,xxx,xxx,configuration);
try{
String fileUrl = aliyunOssClient.getObject(bucketName,filePath).getResponse().getUri();
}catch (Throwable cause){
// here will be catch
cause.printStackTrace();
}
the wrong code to catch exception:
OSS aliyunOssClient = new OSSClientBuilder().build(xxx,xxx,xxx);
try{
String fileUrl = aliyunOssClient.getObject(bucketName,filePath).getResponse().getUri();
}catch (Throwable cause){
// here will not be catch,the thread will be block until dead
cause.printStackTrace();
}
JokerForCode commented
That is the solution
public class ClientConfiguration {
...omit some code...
public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT = 5 * 60 * 1000;
public static final int DEFAULT_CONNECTION_TIMEOUT = 50 * 1000;
}
JokerForCode commented
Hello,Anybody here?