Add 5s timeout for all requests but attachment up/down, avatar (#1584)
* Remove hang workaround in api.js since we have global workaround * Add 5s timeout for all requests exept attachment up/down, avatar
This commit is contained in:
parent
af8b0164b5
commit
735aec90e8
2 changed files with 24 additions and 40 deletions
|
@ -37461,22 +37461,8 @@ var TextSecureServer = (function() {
|
|||
return true;
|
||||
}
|
||||
|
||||
// On Linux/Electron multiple quick web requests can result in the Node.js event
|
||||
// loop getting wedged. Bug: https://github.com/electron/electron/issues/10570
|
||||
// This forces the event loop to move.
|
||||
function scheduleHangWorkaround() {
|
||||
setTimeout(function() {
|
||||
setImmediate(function() {
|
||||
// noop
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function createSocket(url) {
|
||||
var requestOptions = { ca: window.config.certificateAuthorities };
|
||||
|
||||
scheduleHangWorkaround();
|
||||
|
||||
return new nodeWebSocket(url, null, null, null, requestOptions);
|
||||
}
|
||||
|
||||
|
@ -37488,11 +37474,14 @@ var TextSecureServer = (function() {
|
|||
url = options.host + '/' + options.path;
|
||||
}
|
||||
console.log(options.type, url);
|
||||
var timeout = typeof options.timeout !== 'undefined' ? options.timeout : 5000;
|
||||
|
||||
var fetchOptions = {
|
||||
method: options.type,
|
||||
body: options.data || null,
|
||||
headers: { 'X-Signal-Agent': 'OWD' },
|
||||
agent: new httpsAgent({ca: options.certificateAuthorities})
|
||||
agent: new httpsAgent({ca: options.certificateAuthorities}),
|
||||
timeout: timeout
|
||||
};
|
||||
|
||||
if (fetchOptions.body instanceof ArrayBuffer) {
|
||||
|
@ -37531,7 +37520,7 @@ var TextSecureServer = (function() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if ( 0 <= response.status && response.status < 400) {
|
||||
if (0 <= response.status && response.status < 400) {
|
||||
console.log(options.type, url, response.status, 'Success');
|
||||
resolve(result, response.status);
|
||||
} else {
|
||||
|
@ -37544,7 +37533,6 @@ var TextSecureServer = (function() {
|
|||
console.log(e);
|
||||
reject(HTTPError(0, e.toString(), options.stack));
|
||||
});
|
||||
scheduleHangWorkaround();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -37620,7 +37608,8 @@ var TextSecureServer = (function() {
|
|||
user : this.username,
|
||||
password : this.password,
|
||||
validateResponse: param.validateResponse,
|
||||
certificateAuthorities: window.config.certificateAuthorities
|
||||
certificateAuthorities: window.config.certificateAuthorities,
|
||||
timeout : param.timeout
|
||||
}).catch(function(e) {
|
||||
var code = e.code;
|
||||
if (code === 200) {
|
||||
|
@ -37669,7 +37658,8 @@ var TextSecureServer = (function() {
|
|||
type : "GET",
|
||||
responseType: "arraybuffer",
|
||||
contentType : "application/octet-stream",
|
||||
certificateAuthorities: window.config.certificateAuthorities
|
||||
certificateAuthorities: window.config.certificateAuthorities,
|
||||
timeout: 0
|
||||
});
|
||||
},
|
||||
requestVerificationSMS: function(number) {
|
||||
|
@ -37827,7 +37817,8 @@ var TextSecureServer = (function() {
|
|||
httpType : 'GET',
|
||||
urlParameters : '/' + id,
|
||||
responseType : 'json',
|
||||
validateResponse : {location: 'string'}
|
||||
validateResponse : {location: 'string'},
|
||||
timeout : 0
|
||||
}).then(function(response) {
|
||||
return ajax(response.location, {
|
||||
type : "GET",
|
||||
|
@ -37841,6 +37832,7 @@ var TextSecureServer = (function() {
|
|||
call : 'attachment',
|
||||
httpType : 'GET',
|
||||
responseType : 'json',
|
||||
timeout : 0
|
||||
}).then(function(response) {
|
||||
return ajax(response.location, {
|
||||
type : "PUT",
|
||||
|
|
|
@ -24,22 +24,8 @@ var TextSecureServer = (function() {
|
|||
return true;
|
||||
}
|
||||
|
||||
// On Linux/Electron multiple quick web requests can result in the Node.js event
|
||||
// loop getting wedged. Bug: https://github.com/electron/electron/issues/10570
|
||||
// This forces the event loop to move.
|
||||
function scheduleHangWorkaround() {
|
||||
setTimeout(function() {
|
||||
setImmediate(function() {
|
||||
// noop
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function createSocket(url) {
|
||||
var requestOptions = { ca: window.config.certificateAuthorities };
|
||||
|
||||
scheduleHangWorkaround();
|
||||
|
||||
return new nodeWebSocket(url, null, null, null, requestOptions);
|
||||
}
|
||||
|
||||
|
@ -51,11 +37,14 @@ var TextSecureServer = (function() {
|
|||
url = options.host + '/' + options.path;
|
||||
}
|
||||
console.log(options.type, url);
|
||||
var timeout = typeof options.timeout !== 'undefined' ? options.timeout : 5000;
|
||||
|
||||
var fetchOptions = {
|
||||
method: options.type,
|
||||
body: options.data || null,
|
||||
headers: { 'X-Signal-Agent': 'OWD' },
|
||||
agent: new httpsAgent({ca: options.certificateAuthorities})
|
||||
agent: new httpsAgent({ca: options.certificateAuthorities}),
|
||||
timeout: timeout
|
||||
};
|
||||
|
||||
if (fetchOptions.body instanceof ArrayBuffer) {
|
||||
|
@ -94,7 +83,7 @@ var TextSecureServer = (function() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if ( 0 <= response.status && response.status < 400) {
|
||||
if (0 <= response.status && response.status < 400) {
|
||||
console.log(options.type, url, response.status, 'Success');
|
||||
resolve(result, response.status);
|
||||
} else {
|
||||
|
@ -107,7 +96,6 @@ var TextSecureServer = (function() {
|
|||
console.log(e);
|
||||
reject(HTTPError(0, e.toString(), options.stack));
|
||||
});
|
||||
scheduleHangWorkaround();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -183,7 +171,8 @@ var TextSecureServer = (function() {
|
|||
user : this.username,
|
||||
password : this.password,
|
||||
validateResponse: param.validateResponse,
|
||||
certificateAuthorities: window.config.certificateAuthorities
|
||||
certificateAuthorities: window.config.certificateAuthorities,
|
||||
timeout : param.timeout
|
||||
}).catch(function(e) {
|
||||
var code = e.code;
|
||||
if (code === 200) {
|
||||
|
@ -232,7 +221,8 @@ var TextSecureServer = (function() {
|
|||
type : "GET",
|
||||
responseType: "arraybuffer",
|
||||
contentType : "application/octet-stream",
|
||||
certificateAuthorities: window.config.certificateAuthorities
|
||||
certificateAuthorities: window.config.certificateAuthorities,
|
||||
timeout: 0
|
||||
});
|
||||
},
|
||||
requestVerificationSMS: function(number) {
|
||||
|
@ -390,7 +380,8 @@ var TextSecureServer = (function() {
|
|||
httpType : 'GET',
|
||||
urlParameters : '/' + id,
|
||||
responseType : 'json',
|
||||
validateResponse : {location: 'string'}
|
||||
validateResponse : {location: 'string'},
|
||||
timeout : 0
|
||||
}).then(function(response) {
|
||||
return ajax(response.location, {
|
||||
type : "GET",
|
||||
|
@ -404,6 +395,7 @@ var TextSecureServer = (function() {
|
|||
call : 'attachment',
|
||||
httpType : 'GET',
|
||||
responseType : 'json',
|
||||
timeout : 0
|
||||
}).then(function(response) {
|
||||
return ajax(response.location, {
|
||||
type : "PUT",
|
||||
|
|
Loading…
Reference in a new issue