Google-cloud-java: Copying file to storage bucket always times out/HTTP/HTTPS proxy setting

Created on 8 Mar 2018  路  3Comments  路  Source: googleapis/google-cloud-java

I am trying to copy a file to storage bucket, but the operation always times out.
I tried increasing various time out parameters but its not helping.
File size is less than 150kb.
Please refer the below code which times out.
storage.list() method times out.

`private void uploadFile(String bucketName, String content) {
    HttpTransportOptions transportOptions = StorageOptions.getDefaultHttpTransportOptions();
    transportOptions = transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000)
            .build();
    StorageOptions storageOptions = StorageOptions.newBuilder()
            .setRetrySettings(retrySettings())
            .setTransportOptions(transportOptions)
            .build();
    Storage storage = storageOptions.getService();

    Page<Bucket> buckets = storage.list(BucketListOption.pageSize(10), BucketListOption.prefix(bucketName));
    for (Bucket bucket : buckets.iterateAll()) {
        InputStream inputStream = new ByteArrayInputStream(content.getBytes());
        bucket.create("file_name", inputStream, "text/plain");
        break;
    }
}
private RetrySettings retrySettings() {
    return RetrySettings.newBuilder().setMaxAttempts(10)
            .setMaxRetryDelay(Duration.ofMillis(30000L))
            .setTotalTimeout(Duration.ofMillis(120000L))
            .setInitialRetryDelay(Duration.ofMillis(250L))
            .setRetryDelayMultiplier(1.0)
            .setInitialRpcTimeout(Duration.ofMillis(120000L))
            .setRpcTimeoutMultiplier(1.0)
            .setMaxRpcTimeout(Duration.ofMillis(120000L))
            .build();
}`

Error stack:
12:12:27.410 [pool-3-thread-1] ERROR org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler [] - Unexpected error occurred in scheduled task.
com.google.cloud.storage.StorageException: connect timed out
at com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:219) ~[google-cloud-storage-1.19.0.jar!/:1.19.0]
at com.google.cloud.storage.spi.v1.HttpStorageRpc.list(HttpStorageRpc.java:314) ~[google-cloud-storage-1.19.0.jar!/:1.19.0]
at com.google.cloud.storage.StorageImpl$6.call(StorageImpl.java:272) ~[google-cloud-storage-1.19.0.jar!/:1.19.0]
at com.google.cloud.storage.StorageImpl$6.call(StorageImpl.java:269) ~[google-cloud-storage-1.19.0.jar!/:1.19.0]
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:89) ~[gax-1.19.0.jar!/:1.19.0]
at com.google.cloud.RetryHelper.run(RetryHelper.java:74) ~[google-cloud-core-1.19.0.jar!/:1.19.0]
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:51) ~[google-cloud-core-1.19.0.jar!/:1.19.0]
at com.google.cloud.storage.StorageImpl.listBuckets(StorageImpl.java:268) ~[google-cloud-storage-1.19.0.jar!/:1.19.0]
at com.google.cloud.storage.StorageImpl.list(StorageImpl.java:257) ~[google-cloud-storage-1.19.0.jar!/:1.19.0]

Most helpful comment

After setting up the http/https proxy in the application, it works out.
At the start of java application, setting below system properties solves this problem.

    System.setProperty("http.proxyHost", "proxy-host-name");
    System.setProperty("http.proxyPort", "proxy-host-port");
    System.setProperty("https.proxyHost", "proxy-host-name");
    System.setProperty("https.proxyPort", "proxy-host-port");

All 3 comments

After setting up the http/https proxy in the application, it works out.
At the start of java application, setting below system properties solves this problem.

    System.setProperty("http.proxyHost", "proxy-host-name");
    System.setProperty("http.proxyPort", "proxy-host-port");
    System.setProperty("https.proxyHost", "proxy-host-name");
    System.setProperty("https.proxyPort", "proxy-host-port");

Hi @pgbhagat thanks for the letting us know. I wasn't able to repro this issue, so may I ask about your environment settings? (Are you running on any google cloud machines or are you running locally?)

I was running my program behind the firewall, and setting those http proxy settings in application solves the problem. Closing this issue now.

Was this page helpful?
0 / 5 - 0 ratings