Search code examples
node.jsamazon-s3uploadmultipartknox-amazon-s3-client

Nodejs Amazon Upload using Knox crashing at Assertion Error


I'm using the knox amazon uploader as a "proxy" to upload a sliced file from Javascript. But the thing that've noticing is that sometimes ( sadly sometimes so I cannot identify the error exactly) when the response.statusCode isn't 200 the nodeJS crashes at an exception:

assert.js:93 throw new assert.AssertionError({

AssertionError: true == false at IncomingMessage.
(http.js:1341:9) at IncomingMessage.emit (events.js:61:17) at
HTTPParser.onMessageComplete (http.js:133:23) at Socket.ondata
(http.js:1231:22) at Socket._onReadable (net.js:683:27) at
IOWatcher.onReadable [as callback] (net.js:177:10)

Does anyone knows why this happens? Is there a way to catch that exception avoiding the server to crash?

Here's some code if it helps:

var request = client.request('PUT', '/' + params.fileName + '?partNumber=' +       params.partNumber + '&uploadId=' + params.uploadId, {
    'Content-Length': req.headers['content-length']
});

req.on('data', function(data){
    request.write(data, 'binary');
});
request.on('response', function(response) {
    if (response.statusCode== 200) { 
        console.log('Part '+ params.partNumber + ' inserted with etag: '+    response.headers.etag);
}
}).end();

Solution

  • This looks to be a bug in node.js < v0.5 where Socket.destroySoon() does not close the socket right away.

    https://github.com/joyent/node/issues/1892