Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added timeout to the connection #87

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/as.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function init(genericAWSClient) {
path: options.path || "/",
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
secure: options.secure
secure: options.secure,
timeout: options.timeout
});

return {
Expand Down
7 changes: 6 additions & 1 deletion lib/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function genericAWSClient(obj) {
var agent = obj.agent;
var secretAccessKey = obj.secretAccessKey;
var secure = obj.secure == null ? true : false;
var timeout = obj.timeout == null ? 0 : obj.timeout;
var connection = secure ? https : http;

return {call: call};
Expand All @@ -62,7 +63,7 @@ function genericAWSClient(obj) {
next.apply(null, arguments);
}
})(callback)

// Try to set credentials with metadata API if no credentials provided
metadata.readCredentials(obj, function(err) {
if (err) return callback(err);
Expand Down Expand Up @@ -106,6 +107,10 @@ function genericAWSClient(obj) {
})
res.addListener('error', callback)
});
req.setTimeout(timeout,function(){
req.abort();
callback(new Error('Socket timeout occured'));
});
req.write(body)
req.addListener('error', callback)
req.end()
Expand Down
3 changes: 2 additions & 1 deletion lib/cfn.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function init(genericAWSClient) {
path: options.path || "/",
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
secure: options.secure
secure: options.secure,
timeout: options.timeout
});

return {
Expand Down
3 changes: 2 additions & 1 deletion lib/cw.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function init(genericAWSClient) {
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
secure: options.secure,
token: options.token
token: options.token,
timeout: options.timeout
});

return {
Expand Down
3 changes: 2 additions & 1 deletion lib/ec2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function init(genericAWSClient) {
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
secure: options.secure,
token: options.token
token: options.token,
timeout: options.timeout
});

return {
Expand Down
3 changes: 2 additions & 1 deletion lib/elb.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function init(genericAWSClient) {
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
secure: options.secure,
token: options.token
token: options.token,
timeout: options.timeout
});

return {
Expand Down
3 changes: 2 additions & 1 deletion lib/emr.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function init(genericAWSClient) {
path: options.path || "/",
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
secure: options.secure
secure: options.secure,
timeout: options.timeout
});

return {
Expand Down
3 changes: 2 additions & 1 deletion lib/iam.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function init(genericAWSClient) {
path: options.path || "/",
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
secure: options.secure
secure: options.secure,
timeout: options.timeout
});

return {
Expand Down
5 changes: 3 additions & 2 deletions lib/prodAdv.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function init(genericAWSClient) {
path: options.path || "/onca/xml",
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
secure: options.secure
secure: options.secure,
timeout: options.timeout
});

return {
Expand All @@ -28,4 +29,4 @@ function init(genericAWSClient) {
return client.call(action, query, callback);
}
}
}
}
3 changes: 2 additions & 1 deletion lib/ses.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function init(genericAWSClient) {
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
secure: options.secure,
signHeader: true
signHeader: true,
timeout: options.timeout
});

return {
Expand Down
5 changes: 3 additions & 2 deletions lib/simpledb.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function init(genericAWSClient) {
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
secure: options.secure,
token: options.token
token: options.token,
timeout: options.timeout
});

return {
Expand All @@ -28,4 +29,4 @@ function init(genericAWSClient) {
return client.call(action, query, callback);
}
}
}
}
13 changes: 7 additions & 6 deletions lib/sns.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ function init(genericAWSClient) {
options = options || {};

var client = genericAWSClient({
host: options.host || "sns.us-east-1.amazonaws.com",
path: options.path || "/",
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
secure: options.secure,
version: options.version
host: options.host || "sns.us-east-1.amazonaws.com",
path: options.path || "/",
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
secure: options.secure,
version: options.version,
timeout: options.timeout
});

return {
Expand Down
3 changes: 2 additions & 1 deletion lib/sqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function init(genericAWSClient) {
secretAccessKey: secretAccessKey,
secure: options.secure,
agent: options.agent,
token: options.token
token: options.token,
timeout: options.timeout
});

return {
Expand Down
3 changes: 2 additions & 1 deletion lib/sts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function init(genericAWSClient) {
path: options.path || "/",
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
secure: options.secure
secure: options.secure,
timeout: options.timeout
});

return {
Expand Down