Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon sqs throwing exception connection reset

I am using AmazonSQSAsyncClient to connect with Amazon SQS, but sometimes I see the following execution in the logs:

INFO  [AmazonHttpClient:444] Unable to execute HTTP request: Connection reset
java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
    at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:755)
    at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:166)
    at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:90)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:281)
    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:92)
    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:62)
    at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254)
    at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289)
    at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252)
    at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191)
    at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300)
    at com.amazonaws.http.protocol.SdkHttpRequestExecutor.doReceiveResponse(SdkHttpRequestExecutor.java:66)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127)
    at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:712)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:517)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:380)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:229)
    at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2169)
    at com.amazonaws.services.sqs.AmazonSQSClient.getQueueUrl(AmazonSQSClient.java:468)
    at com.amazonaws.services.sqs.AmazonSQSClient.getQueueUrl(AmazonSQSClient.java:1476)

I am using the AmazonSQSAsyncClient through out the application as singleton.

Code snippet is below.

static{
        if(sqsObj == null){
        sqsObj = new AmazonSQSAsyncClient(new ClasspathPropertiesFileCredentialsProvider("app.properties"));
        sqsObj.setRegion(Region.getRegion(Regions.valueOf("sample region"));
    }
}

By using sqsobj, I am doing operations like create queue, send message and receive messages. It works fine but some time throws the exception as above. After restarting the application it works fine for sometime.

I am using aws-java-sdk-1.7.1. Please suggest on this.

like image 644
user2677325 Avatar asked Jun 03 '14 09:06

user2677325


People also ask

How many times will SQS Retry?

Async Events (such as SQS and SNS): will trigger two retries (by default). If all retries have failed, it's important to save the event somewhere for later processing.

How do I clean my SQS queue?

To purge a queue, log in to the AWS Management Console and choose Amazon SQS. Then, select a queue, and choose “Purge Queue” from the Queue Actions menu. The queue will then be cleared of all messages. You can also purge queues using the AWS SDKs or command-line tools.

What is purging in SQS?

If you don't want to delete an Amazon SQS queue but need to delete all of the messages from it, purge the queue. The message deletion process takes up to 60 seconds. We recommend waiting for 60 seconds regardless of your queue's size. Important. When you purge a queue, you can't retrieve any of the deleted messages.

Can SQS lose message?

An SQS Queue can also be configured with a Message Retention Period in seconds. This value specifies how long a message can stay on a queue before it is automatically deleted, regardless of its processing status. The retention period can be set between 60 seconds and 14 days, with the default at 4 days.


1 Answers

The "connection reset" means that the other party (i.e. the server) closed the connection.

Internally the SDK builds and reuses a http connection to not have to open a connection every time you make a request.

The log message tells you that the connection was reset, but normally this is not something to worry about. The SDK will retry automatically in cases like this. So if you are only seeing this sporadically in the logs but everything works as expected you should probably not worry about it

like image 160
Mircea Avatar answered Sep 26 '22 03:09

Mircea