Skip to content

Commit

Permalink
Add a timeout to outbound requests (#6075)
Browse files Browse the repository at this point in the history
There have been instances where the outbound request handler has hung
completely in production. It's not clear from logging why this occured
and it's not consistent or repeatable, but a good potential option is
that requests to external servers are hanging.

This change adds an explicit timeout to the two outbound IO requests.

Depending on various factors there may already be an implicit timeout,
but this makes it explicit and much shorter (10 seconds).

#6025
  • Loading branch information
Stefan du Fresne committed Oct 29, 2019
1 parent a8aa83f commit db13af1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sentinel/src/schedule/outbound.js
Expand Up @@ -11,6 +11,7 @@ const configService = require('../config'),
lineage = require('@medic/lineage')(Promise, db.medic);

const CONFIGURED_PUSHES = 'outbound';
const OUTBOUND_REQ_TIMEOUT = 10 * 1000;

const fetchPassword = key => {
return secureSettings.getCredentials(key).then(password => {
Expand All @@ -24,8 +25,8 @@ const fetchPassword = key => {
// Returns an object containing:
// validTasks: an array of tasks and their hydrated docs as {task doc} objects
// invalidTasks: an array of tasks whose documents have been deleted
const queuedTasks = () =>
db.sentinel.allDocs({
const queuedTasks = () => {
return db.sentinel.allDocs({
startkey: 'task:outbound:',
endkey: 'task:outbound:\ufff0',
include_docs: true
Expand Down Expand Up @@ -71,6 +72,7 @@ const queuedTasks = () =>
}
});
});
};

// Maps a source document to a destination format using the given push config
const mapDocumentToPayload = (doc, config, key) => {
Expand Down Expand Up @@ -129,7 +131,8 @@ const send = (payload, config) => {
const sendOptions = {
url: urlJoin(config.destination.base_url, config.destination.path),
body: payload,
json: true
json: true,
timeout: OUTBOUND_REQ_TIMEOUT
};

const auth = () => {
Expand Down Expand Up @@ -163,7 +166,8 @@ const send = (payload, config) => {
password: password
},
url: urlJoin(config.destination.base_url, authConf.path),
json: true
json: true,
timeout: OUTBOUND_REQ_TIMEOUT
};

return request.post(authOptions)
Expand Down

0 comments on commit db13af1

Please sign in to comment.