aws-sdk-java icon indicating copy to clipboard operation
aws-sdk-java copied to clipboard

Gzip compression doesn't work with DynamoDB (crc32 errors)

Open jakozaur opened this issue 11 years ago • 49 comments

If you setup gzip, sometimes I get an exception:

Caused by: com.amazonaws.internal.CRC32MismatchException: Client calculated crc32 checksum didn't match that calculated by server side
    at com.amazonaws.http.JsonResponseHandler.handle(JsonResponseHandler.java:112)
    at com.amazonaws.http.JsonResponseHandler.handle(JsonResponseHandler.java:42)
    at com.amazonaws.http.AmazonHttpClient.handleResponse(AmazonHttpClient.java:1072)
    at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:746)
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:489)

Android SDK fixed that bug. See: https://github.com/aws/aws-sdk-android/pull/40 and the actual fix: https://github.com/aws/aws-sdk-android/commit/b03c51e6fd413b885de513443600671ecd2cce3d

Please also fix it in Java SDK.

jakozaur avatar Oct 05 '15 10:10 jakozaur

Hi @aws team,

We are also impacted by this bug. Please fix this :+1:

sarxos avatar Nov 10 '15 11:11 sarxos

I've also noticed this while trying to use it with Kinesis streaming. Since the easiest way to set up the KCL is with a common client for Kinesis, DynamoDB and CloudWatch, it means that you need to disable Gzip compression for all three of those, which is not ideal.

2015-12-22_10:43:25.44544 Dec 22, 2015 10:43:25 AM com.amazonaws.services.kinesis.clientlibrary.lib.worker.ShardSyncTask call
2015-12-22_10:43:25.44546 SEVERE: Caught exception while sync'ing Kinesis shards and leases
2015-12-22_10:43:25.44547 com.amazonaws.services.kinesis.leases.exceptions.DependencyException: com.amazonaws.AmazonClientException: Unable to execute HTTP request: Client calculated crc32 checksum didn't match that calculated by server side
2015-12-22_10:43:25.44548   at com.amazonaws.services.kinesis.leases.impl.LeaseManager.list(LeaseManager.java:268)
2015-12-22_10:43:25.44549   at com.amazonaws.services.kinesis.leases.impl.LeaseManager.listLeases(LeaseManager.java:203)
2015-12-22_10:43:25.44549   at com.amazonaws.services.kinesis.clientlibrary.lib.worker.ShardSyncer.syncShardLeases(ShardSyncer.java:119)
2015-12-22_10:43:25.44550   at com.amazonaws.services.kinesis.clientlibrary.lib.worker.ShardSyncer.checkAndCreateLeasesForNewShards(ShardSyncer.java:88)
2015-12-22_10:43:25.44551   at com.amazonaws.services.kinesis.clientlibrary.lib.worker.ShardSyncTask.call(ShardSyncTask.java:68)
2015-12-22_10:43:25.44551   at com.amazonaws.services.kinesis.clientlibrary.lib.worker.MetricsCollectingTaskDecorator.call(MetricsCollectingTaskDecorator.java:49)
2015-12-22_10:43:25.44553   at com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker.initialize(Worker.java:383)
2015-12-22_10:43:25.44553   at com.amazonaws.services.kinesis.clientlibrary.lib.worker.Worker.run(Worker.java:318)
2015-12-22_10:43:25.44554   at com.X.Y.Z.main(Z.java:137)
2015-12-22_10:43:25.44555 Caused by: com.amazonaws.AmazonClientException: Unable to execute HTTP request: Client calculated crc32 checksum didn't match that calculated by server side
2015-12-22_10:43:25.44557   at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:587)
2015-12-22_10:43:25.44568   at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:362)
2015-12-22_10:43:25.44569   at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:328)
2015-12-22_10:43:25.44570   at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:307)
2015-12-22_10:43:25.44570   at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:1805)
2015-12-22_10:43:25.44571   at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.scan(AmazonDynamoDBClient.java:1525)
2015-12-22_10:43:25.44572   at com.amazonaws.services.kinesis.leases.impl.LeaseManager.list(LeaseManager.java:227)
2015-12-22_10:43:25.44573   ... 8 more
2015-12-22_10:43:25.44575 Caused by: com.amazonaws.internal.CRC32MismatchException: Client calculated crc32 checksum didn't match that calculated by server side
2015-12-22_10:43:25.44576   at com.amazonaws.http.JsonResponseHandler.handle(JsonResponseHandler.java:113)
2015-12-22_10:43:25.44576   at com.amazonaws.http.JsonResponseHandler.handle(JsonResponseHandler.java:42)
2015-12-22_10:43:25.44577   at com.amazonaws.http.AmazonHttpClient.handleResponse(AmazonHttpClient.java:1142)
2015-12-22_10:43:25.44589   at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:853)
2015-12-22_10:43:25.44592   at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:576)
2015-12-22_10:43:25.44594   ... 14 more

ohookins avatar Dec 22 '15 10:12 ohookins

It looks like a bug in java sdk, will fix that. Thanks for the report.

zhangzhx avatar Dec 22 '15 18:12 zhangzhx

Hello @jakozaur , can you give us a specific test case ? I am working on fixing this.

zhangzhx avatar Dec 22 '15 18:12 zhangzhx

@zhangzhx I'm hitting it every time, when I enable Gzip compression and than try to use DynamoDB Api.

I just created DynamoDB client:

new AmazonDynamoDBClient(credentials, new ClientConfiguration().withGzip(true))

and then every network call fails.

jakozaur avatar Dec 23 '15 09:12 jakozaur

https://github.com/aws/aws-sdk-js/issues/405 is probably relevant to your interests. DynamoDB is returning a checksum of the compressed bytes, which many HTTP clients transparently decompress for you making the checksum "wrong". Ideally they would switch to returning a checksum over the uncompressed bytes, but until that happens the only real option is to disable checksum validation when you might get a gzipped response. :(

fernomac avatar Dec 23 '15 13:12 fernomac

Oh bother, didn't see the linked Android SDK issue. It's unfortunate that they fixed this client-side and are now depending on the checksum matching the compressed bytes, as that pretty much closes the door on a fix coming from the server-side. If you have a reasonable way of getting the compressed bytes out of the Apache HttpClient, you may as well follow suit and verify the checksum on that.

fernomac avatar Dec 23 '15 14:12 fernomac

Thanks @fernomac for the explain.

I will reach out to the DynamoDB server team and figure out a safe way to fix this and not breaking android as well. Maybe letting them send both CRCs from uncompressed and compressed payload would be an option.

zhangzhx avatar Dec 23 '15 20:12 zhangzhx

@zhangzhx, could you please let us know if there is any update? Thank you in advance.

iCesofT avatar Mar 31 '16 11:03 iCesofT

Also hitting this. Any status on a fix?

bcarl avatar Apr 16 '16 01:04 bcarl

Sorry for the long wait. We asked the service team and they are not planning to change the checksum to uncompressed data. We will soon migrate our underlying Apache Httpclient from 4.3.6 to a newer version 4.5. With that said, we will fix this issue in the new Httpclient by disabling response content automatic decompression for dynamo. I will let you know once that happens.

zhangzhx avatar Apr 21 '16 18:04 zhangzhx

+1 :)

jorgebsa avatar May 17 '16 18:05 jorgebsa

We have fixed this bug in our latest release 1.11.20. Please try the new version and let us know if you have further questions. Sorry for the long waiting of the bug fix.

zhangzhx avatar Jul 22 '16 00:07 zhangzhx

I think you actually may have introduced a bigger bug.... out of the blue once we updated to 1.11.20 we started seeing this issue (when previously we were not).

theRealDrumBum avatar Jul 22 '16 23:07 theRealDrumBum

Hi @theRealDrumBum, can you give me a detailed description what the issue you are seeing?

zhangzhx avatar Jul 22 '16 23:07 zhangzhx

Its basically the same issue reported above, except introduced with 1.11.20...

stack-trace.txt

theRealDrumBum avatar Jul 22 '16 23:07 theRealDrumBum

Can you give me some sample code to reproduce this bug? Thanks.

zhangzhx avatar Jul 23 '16 00:07 zhangzhx

Any details about how you've configured the client would be very helpful as well.

breedloj avatar Jul 25 '16 19:07 breedloj

I can help out, we are having the same issue. Version 1.11.21 in a spring-boot 1.4.rc1 project.

In a Spring app:

@Configuration
public class AwsConfig {

    @Bean
    public AWSCredentialsProvider awsCredentialsProvider() {
        return new DefaultAWSCredentialsProviderChain();
    }

    @Bean
    public AmazonDynamoDBAsyncClient client(final AWSCredentialsProvider credentialsProvider,
                                            final DynamoDBConfig dynamoDBConfig) {
        final ClientConfiguration configuration = new ClientConfiguration();
        configuration.setRequestTimeout(dynamoDBConfig.getTimeoutInMillis());
        configuration.setClientExecutionTimeout(dynamoDBConfig.getTimeoutInMillis());
        final AmazonDynamoDBAsyncClient client = new AmazonDynamoDBAsyncClient(credentialsProvider, configuration);
        client.setRegion(Region.getRegion(Regions.fromName(dynamoDBConfig.getRegion())));
        return client;
    }
}

And somewhere else, the exception mentioned above when executing:

GetItemResult getItemRes = client.getItem(
                new GetItemRequest(settingsTable, ImmutableMap.of(SETTINGS_ID_KEY, new AttributeValue().withS(SETTINGS_NEWER_URL_ID)))
        );

Exception:

com.amazonaws.AmazonClientException: Unable to execute HTTP request: Client calculated crc32 checksum didn't match that calculated by server side
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:735)
    at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:475)
    at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:437)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:386)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:2074)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:2044)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.getItem(AmazonDynamoDBClient.java:1392)
Caused by: com.amazonaws.internal.CRC32MismatchException: Client calculated crc32 checksum didn't match that calculated by server side
    at com.amazonaws.http.JsonResponseHandler.handle(JsonResponseHandler.java:125)
    at com.amazonaws.http.JsonResponseHandler.handle(JsonResponseHandler.java:46)
    at com.amazonaws.http.AmazonHttpClient.handleResponse(AmazonHttpClient.java:1274)
    at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:913)
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:723)

thisismana avatar Jul 29 '16 18:07 thisismana

Which versions of the aws-java-sdk-dynamodb and aws-java-sdk-core are being used at runtime?

shorea avatar Jul 29 '16 18:07 shorea