Skip to content

Commit

Permalink
Timeouts
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Juszczak <[email protected]>
  • Loading branch information
Juszczak committed Jul 24, 2020
1 parent d17eabf commit 4c14995
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/git-jira-commit-msg.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const verbose = !process.env.GIT_JIRA_SILENT;
const username = process.env.GIT_JIRA_USER;
const password = process.env.GIT_JIRA_PASSWORD;
const url = process.env.GIT_JIRA_URL;
const timeout = +process.env.GIT_JIRA_TIMEOUT || 5000;
const eol = process.env.GIT_JIRA_EOL;
const timeout = +process.env.GIT_JIRA_TIMEOUT || 6000;
const eol = !!eval(process.env.GIT_JIRA_EOL);

function print(io, message) {
io.write(`${message}${eol ? '' : EOL}`);
Expand Down Expand Up @@ -54,9 +54,9 @@ const auth = `${username}:${password}`;
const headers = { 'Content-Type': 'application/json' };
const path = `/rest/api/2/search?jql=assignee=${username}`;

const request = { auth, headers, hostname, port, path, timeout };
const requestOpts = { auth, headers, hostname, port, path, timeout };

get(request, (message) => {
const request = get(requestOpts, (message) => {
let data = '';

message.on('data', (chunk) => {
Expand All @@ -68,7 +68,12 @@ get(request, (message) => {
});

message.on('timeout', () => {
error(6, 'Request timeout.');
error(6, 'Incomming message timeout.');
});

message.on('socket', (socket) => {
socket.setTimeout(timeout, () => socket.destroy());
error(6, 'Incomming message socket timeout');
});

message.on('end', () => {
Expand Down Expand Up @@ -97,3 +102,10 @@ get(request, (message) => {
}
});
});

request.on('socket', (socket) => {
socket.setTimeout(timeout, () => {
socket.destroy();
error(10, 'Request socket timeout.');
});
});

0 comments on commit 4c14995

Please sign in to comment.