Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  • 4 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 15 additions and 11 deletions.
  1. +15 −11 lib/index.js
View
26 lib/index.js
@@ -203,9 +203,10 @@ S3.prototype.putTile = function(z, x, y, data, callback) {
var stats = this._stats;
- var failed;
- var error = function(err) {
- failed = true;
+ var called;
+ var cb = function(err) {
+ if (called) return;
+ called = true;
if (!err) return callback();
if (this.data.retry) {
setTimeout(function() {
@@ -229,19 +230,22 @@ S3.prototype.putTile = function(z, x, y, data, callback) {
'Content-Length': grid ? Buffer.byteLength(data, 'utf8') : data.length,
'Content-Type': grid ? 'text/html' : 'image/png'
});
- req.once('close', error);
- req.once('error', error);
+ req.on('close', cb);
+ req.on('error', cb);
req.setTimeout(60e3, function() {
- req.emit('error', new Error('Timeout 60s.'));
+ req.abort();
+ var err = new Error('ESOCKETTIMEDOUT');
+ err.code = 'ESOCKETTIMEDOUT';
+ req.emit('error', err);
});
- req.once('response', function(res) {
- if (failed) return false;
+ req.on('response', function(res) {
+ res.on('error', cb);
if (res.statusCode === 200) {
stats.put++;
stats.txout += data.length;
- return callback();
+ return cb();
}
- return error(new Error('S3 put failed: ' + res.statusCode));
+ return cb(new Error('S3 put failed: ' + res.statusCode));
});
req.end(data);
}.bind(this);
@@ -258,7 +262,7 @@ S3.prototype.putTile = function(z, x, y, data, callback) {
var newmd5 = crypto.createHash('md5').update(data).digest('hex');
if (oldmd5 === newmd5) {
stats.noop++;
- return callback();
+ return cb();
}
// Old tile buffer does not match new. PUT.
return put();

No commit comments for this range

Something went wrong with that request. Please try again.