ECS EC2 环境中的 AWS Java SDK 异步客户端

问题描述 投票:0回答:1

我尝试将 java 服务从 beanstalk 迁移到 ECS。

不幸的是,所使用的异步客户端似乎不是这样工作的。我也尝试更新到最新版本(software.amazon.awssdk:bom:2.13.8)但没有效果。

为了测试,我使用普通客户端创建了一个端点,并为

com.amazonaws.request
software.amazon.awssdk
启用了调试日志记录。

使用普通客户端,它可以按预期工作,我在日志文件中看到以下过程

2020-05-04 06:38:33.380 DEBUG 1 --- [oundedElastic-8] software.amazon.awssdk.request           : Sending Request: DefaultSdkHttpFullRequest(httpMethod=POST, protocol=https, host=dynamodb.eu-central-1.amazonaws.com, encodedPath=/, headers=[amz-sdk-invocation-id, Content-Length, Content-Type, User-Agent, X-Amz-Target], queryParameters=[])
2020-05-04 06:38:33.386 DEBUG 1 --- [oundedElastic-8] s.amazon.awssdk.auth.signer.Aws4Signer   : AWS4 String to sign: AWS4-HMAC-SHA256
20200504T063833Z
20200504/eu-central-1/dynamodb/aws4_request
8f5568b71452990c24ec92f13e06416df55b0725c456484837c7d34c77e312d1
2020-05-04 06:38:33.389 DEBUG 1 --- [oundedElastic-8] s.a.a.h.a.i.conn.SdkTlsSocketFactory     : Connecting socket to dynamodb.eu-central-1.amazonaws.com/52.94.17.148:443 with timeout 2000
2020-05-04 06:38:33.390 DEBUG 1 --- [oundedElastic-8] s.a.a.h.a.i.conn.SdkTlsSocketFactory     : Enabled protocols: [TLSv1.3, TLSv1.2, TLSv1.1, TLSv1]
2020-05-04 06:38:33.392 DEBUG 1 --- [oundedElastic-8] s.a.a.h.a.i.conn.SdkTlsSocketFactory     : Enabled cipher suites:[TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_DSS_WITH_AES_256_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
2020-05-04 06:38:33.392 DEBUG 1 --- [oundedElastic-8] s.a.a.h.a.i.conn.SdkTlsSocketFactory     : socket.getSupportedProtocols(): [TLSv1.3, TLSv1.2, TLSv1.1, TLSv1, SSLv3, SSLv2Hello], socket.getEnabledProtocols(): [TLSv1.3, TLSv1.2, TLSv1.1, TLSv1]
2020-05-04 06:38:33.393 DEBUG 1 --- [oundedElastic-8] s.a.a.h.a.i.conn.SdkTlsSocketFactory     : TLS protocol enabled for SSL handshake: [TLSv1.2, TLSv1.1, TLSv1, TLSv1.3]
2020-05-04 06:38:33.393 DEBUG 1 --- [oundedElastic-8] s.a.a.h.a.i.conn.SdkTlsSocketFactory     : Starting handshake
2020-05-04 06:38:33.448 DEBUG 1 --- [oundedElastic-8] s.a.a.h.a.i.conn.SdkTlsSocketFactory     : Secure session established
2020-05-04 06:38:33.448 DEBUG 1 --- [oundedElastic-8] s.a.a.h.a.i.conn.SdkTlsSocketFactory     :  negotiated protocol: TLSv1.2
2020-05-04 06:38:33.448 DEBUG 1 --- [oundedElastic-8] s.a.a.h.a.i.conn.SdkTlsSocketFactory     :  negotiated cipher suite: TLS_RSA_WITH_AES_128_GCM_SHA256
2020-05-04 06:38:33.449 DEBUG 1 --- [oundedElastic-8] s.a.a.h.a.i.conn.SdkTlsSocketFactory     :  peer principal: CN=dynamodb.eu-central-1.amazonaws.com
2020-05-04 06:38:33.449 DEBUG 1 --- [oundedElastic-8] s.a.a.h.a.i.conn.SdkTlsSocketFactory     :  peer alternative names: [dynamodb.eu-central-1.amazonaws.com, *.ddb.eu-central-1.amazonaws.com]
2020-05-04 06:38:33.449 DEBUG 1 --- [oundedElastic-8] s.a.a.h.a.i.conn.SdkTlsSocketFactory     :  issuer principal: CN=Amazon, OU=Server CA 1B, O=Amazon, C=US
2020-05-04 06:38:33.449 DEBUG 1 --- [oundedElastic-8] s.a.a.h.a.internal.net.SdkSslSocket      : created: dynamodb.eu-central-1.amazonaws.com/52.94.17.148:443
2020-05-04 06:38:33.486 DEBUG 1 --- [oundedElastic-8] software.amazon.awssdk.request           : Received successful response: 200

在异步客户端中,请求立即结束并出现错误

Channel was closed before it could be written to.

2020-05-04 06:46:30.278 DEBUG 1 --- [ledExecutor-4-0] software.amazon.awssdk.request           : Retrying Request: DefaultSdkHttpFullRequest(httpMethod=POST, protocol=https, host=dynamodb.eu-central-1.amazonaws.com, encodedPath=/, headers=[amz-sdk-invocation-id, Content-Length, Content-Type, User-Agent, X-Amz-Target], queryParameters=[])
2020-05-04 06:46:30.280 DEBUG 1 --- [ledExecutor-4-0] s.amazon.awssdk.auth.signer.Aws4Signer   : AWS4 String to sign: AWS4-HMAC-SHA256
20200504T064630Z
20200504/eu-central-1/dynamodb/aws4_request
c0690ccc235e73f0a118bcaf7f2ffd435490e4511b5c3f78b60ee244c0d9f24d
2020-05-04 06:46:30.323 DEBUG 1 --- [tyEventLoop-3-1] s.a.a.h.n.n.i.NettyRequestExecutor       : Channel was closed before it could be written to.
java.io.IOException: Channel was closed before it could be written to.
    at software.amazon.awssdk.http.nio.netty.internal.NettyRequestExecutor.tryConfigurePipeline(NettyRequestExecutor.java:190) ~[netty-nio-client-2.13.8.jar:na]
    at software.amazon.awssdk.http.nio.netty.internal.NettyRequestExecutor.makeRequestListener(NettyRequestExecutor.java:138) ~[netty-nio-client-2.13.8.jar:na]
    at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:577) ~[netty-common-4.1.48.Final.jar:4.1.48.Final]
    at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:551) ~[netty-common-4.1.48.Final.jar:4.1.48.Final]
    at io.netty.util.concurrent.DefaultPromise.access$200(DefaultPromise.java:35) ~[netty-common-4.1.48.Final.jar:4.1.48.Final]
    at io.netty.util.concurrent.DefaultPromise$1.run(DefaultPromise.java:501) ~[netty-common-4.1.48.Final.jar:4.1.48.Final]
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164) ~[netty-common-4.1.48.Final.jar:4.1.48.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) ~[netty-common-4.1.48.Final.jar:4.1.48.Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) ~[netty-transport-4.1.48.Final.jar:4.1.48.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.48.Final.jar:4.1.48.Final]
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.48.Final.jar:4.1.48.Final]
    at java.base/java.lang.Thread.run(Unknown Source) ~[na:na]
2020-05-04 06:46:30.327 DEBUG 1 --- [tyEventLoop-3-1] software.amazon.awssdk.request           : Retryable error detected. Will retry in 33ms. Request attempt number 3
...

这两个客户端都是在没有特殊配置的情况下创建的。

DynamoDbAsyncClient.create();

有人可以告诉我如何避免这个错误吗?

amazon-web-services amazon-dynamodb aws-sdk amazon-ecs aws-sdk-java-2.0
1个回答
0
投票

在高速复制对象时,我在 s3 async clint 上遇到了类似的问题,这是我最终得到的配置


S3AsyncClient.builder() 
   .httpClientBuilder( NettyNioAsyncHttpClient.builder() 
       .connectionMaxIdleTime(Duration.ofSeconds(180)) 
       .connectionAcquisitionTimeout(Duration.ofSeconds(60)) 
       .connectionTimeout(Duration.ofSeconds(120)) .maxConcurrency(120) 
       .maxPendingConnectionAcquires(50000)
   ) 
    .overrideConfiguration( ClientOverrideConfiguration.builder() 
        .retryPolicy( RetryPolicy.builder() 
           .backoffStrategy(BackoffStrategy.defaultStrategy()) 
           .throttlingBackoffStrategy(BackoffStrategy.defaultThrottlingStrategy()) 
           .numRetries(5) 
           .retryCondition(RetryCondition.defaultRetryCondition()) 
.build() 
) 
.apiCallTimeout(Duration.ofSeconds(120)) .build()) .build();

© www.soinside.com 2019 - 2024. All rights reserved.