Aws-sdk-js: SQS sendmessage returns InvalidChecksum with apparently valid message

Created on 7 Oct 2015  路  9Comments  路  Source: aws/aws-sdk-js

I should mention that my code was working well with SQS before and only recently returns this error object:

{
    "message": "sendMessage returned an invalid MD5 response. Got \"undefined\", expecting \"4c7178998961f02210ca0a798f19f004\".",
    "retryable": true,
    "code": "InvalidChecksum",
    "messageIds": [
        null
    ],
    "time": "2015-10-07T13:53:38.299Z",
    "statusCode": 200
}

I reduced my code for testing and I am quite convinced that i am not sending in any invalid characters (UTF-8) per http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html.
Here is a reduction of my code (that was formerly working fine):

var credentials = {
    accessKeyId: "***",
    region: "us-west-2",
    secretAccessKey: "***"
};
var message =  {
    email: {
        to:["[email protected]"],
        locals: {},
        template: {
            html:true,
            Body:"<<SUBJ>>test<</SUBJ>><<TEXT>>test<</TEXT>><<STYL>><</STYL>><<HTML>>test<</HTML>>"
        }
    }
};
message = JSON.stringify( message );
var queue = "https://sqs.us-west-2.amazonaws.com/***/notifications_email"
var params = {
  MessageBody: message,
  QueueUrl: queue,
  DelaySeconds: 0
};
AWS.config.update(credentials);
var sqs = new AWS.SQS();
sqs.sendMessage ( params, function ( error, data ) {
    next( error, data );
});

Note, I have hidden my accessKeyId, secretAccessKey and queue id (I'm not sending in asterisks).

The error message is not enough to go on - I've searched up and down and can find nothing (related to my problem) about it. Need help please :)

update: i just noticed that while sendMessage returns an error, it is still getting into the Queue (which is probably why the statusCode = 200). More unusual, in some instances I have the same message repeating 3 more times (my worker consumes the messages and sends out email via SES).

also, i found this seemingly related issue with the go sdk although it's resolution seems unclear:
https://github.com/aws/aws-sdk-go/issues/339

just thought of another tidbit of information: i am running this locally on my node server while in development which was accessed at the localhost loopback address (127.0.0.1). I changed my vagrant configuration (recently although I couldn't tell if that change coincides with the error) such that the host now is accessed at an internal class c address ( 192.168.x.x )...

perhaps there is some checking of the request host during creation of the checksum and, not finding a vpn or host at that address on AWS, it fails. If so, I couldn't know that because the documentation doesn't go to those lengths. I suppose I could do another test (change back to localhost) but I'm weary now with this and it could be any number of issues anyway - I'd prefer if an expert could chime in at this point.

closing-soon guidance

Most helpful comment

I have this problem if I send messages in a loop. Even for a loop of 3 items. No error for a single message sent.

All 9 comments

comments? ideas? anyone?

@ReinsBrain
Are you getting this error when sending the exact params you've listed above?

When sendMessage is called, the service returns in the response the MD5 of the MessageBody that was sent in. The SDK calculates an MD5 using the MessageBody supplied in the sendMessage parameters, then compares this MD5 with the value returned from the service. The error you're seeing occurs when the MD5 from the service doesn't match what the SDK calculates.

What's interesting is that your error message contains undefined, which should be the MD5 value returned by the service in the response. This seems to indicate that something went wrong on the service side. Are you still seeing this issue? What version of the SDK are you using? I haven't been able to reproduce your results yet, using node 0.12.7 and SDK v2.2.8.

Apologies for the late response.

Closing this issue, but feel free to comment or open another issue if you have any further questions.

FYI - I was having a similar issue and discovered that it was only happening when I was running a reverse proxy on port 4000 on my localhost.

I am getting this error when enqueuing two items quickly, in parallel basically. One is enqueued without an error and the other had the checksum error, plus it enqueues 4 items (messages). Either message works fine when enqueued separately. I didn't test more than two messages, but it appears that somewhere the requests are not asynchronous.

@sumpton @chrisradek Any updates on this? Still getting this issue while using multiple request to sqs from different asgs.

I have this problem if I send messages in a loop. Even for a loop of 3 items. No error for a single message sent.

I was facing the same issue and resolved it by fixing the parameter scope. Make sure the params object is not shared concurrently.

This snipped wasn't working:

var params = {
    DelaySeconds: 0,
    QueueUrl: QUEUE_URL
};

function sendMessage(body) {
    params.MessageBody = body
    sqs.sendMessage(params, function (err, data) {
        if (err) {
            console.error(err);
        } else {
            console.log("Success", data.MessageId);
        }
    });
}

for (var i = 0; i < messages.length; i++) {
    sendMessage(messages[i]);
}

As you can see, all threads were referencing the same params object. I fixed by creating a new object for each invocation as below:

function sendMessage(body) {
    var params = {
        DelaySeconds: 0,
        MessageBody: body,
        QueueUrl: QUEUE_URL
    };

    sqs.sendMessage(params, function (err, data) {
        if (err) {
            console.error(err);
        } else {
            console.log("Success", data.MessageId);
        }
    });
}

for (var i = 0; i < messages.length; i++) {
    sendMessage(messages[i]);
}

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

Was this page helpful?
0 / 5 - 0 ratings