SaltwaterC/aws2js — Issue #20: un-catchable error: The server prematurely closed the connection.
Author: jahewson
Created: 2012-02-08 10:56:24+00:00
State: open

I'm getting an un-catchable error from the SQS client, after my program has been running for around 30sec...

```
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: The server prematurely closed the connection.
at IncomingMessage. (/Users/john/node_modules/aws2js/lib/internals.js:235:18)
at IncomingMessage.emit (events.js:64:17)
at CleartextStream. (http.js:1170:17)
at CleartextStream.emit (events.js:88:20)
at Array.1 (tls.js:731:22)
at EventEmitter._tickCallback (node.js:192:40)
```

My program is a simple queue consumer:

```
(function poll() {
sqs.request('ReceiveMessage', {}, function(err, result) {
if (err) { throw err; }

if (result.ReceiveMessageResult.Message) {
var handle = result.ReceiveMessageResult.Message.ReceiptHandle;
var body = result.ReceiveMessageResult.Message.Body;

onMessage(body, function() {
sqs.request('DeleteMessage', { ReceiptHandle: handle }, function(err, result) {
if (err) { throw err; }
process.nextTick(poll);
});
});
}
else {
setTimeout(poll, 5*1000);
}
});
})();

function onMessage(body, callback) {
// ... do some work
callback();
}
```