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;
|
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) {
|
function createSocket(url) {
|
||||||
var requestOptions = { ca: window.config.certificateAuthorities };
|
var requestOptions = { ca: window.config.certificateAuthorities };
|
||||||
|
|
||||||
scheduleHangWorkaround();
|
|
||||||
|
|
||||||
return new nodeWebSocket(url, null, null, null, requestOptions);
|
return new nodeWebSocket(url, null, null, null, requestOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37488,11 +37474,14 @@ var TextSecureServer = (function() {
|
||||||
url = options.host + '/' + options.path;
|
url = options.host + '/' + options.path;
|
||||||
}
|
}
|
||||||
console.log(options.type, url);
|
console.log(options.type, url);
|
||||||
|
var timeout = typeof options.timeout !== 'undefined' ? options.timeout : 5000;
|
||||||
|
|
||||||
var fetchOptions = {
|
var fetchOptions = {
|
||||||
method: options.type,
|
method: options.type,
|
||||||
body: options.data || null,
|
body: options.data || null,
|
||||||
headers: { 'X-Signal-Agent': 'OWD' },
|
headers: { 'X-Signal-Agent': 'OWD' },
|
||||||
agent: new httpsAgent({ca: options.certificateAuthorities})
|
agent: new httpsAgent({ca: options.certificateAuthorities}),
|
||||||
|
timeout: timeout
|
||||||
};
|
};
|
||||||
|
|
||||||
if (fetchOptions.body instanceof ArrayBuffer) {
|
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');
|
console.log(options.type, url, response.status, 'Success');
|
||||||
resolve(result, response.status);
|
resolve(result, response.status);
|
||||||
} else {
|
} else {
|
||||||
|
@ -37544,7 +37533,6 @@ var TextSecureServer = (function() {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
reject(HTTPError(0, e.toString(), options.stack));
|
reject(HTTPError(0, e.toString(), options.stack));
|
||||||
});
|
});
|
||||||
scheduleHangWorkaround();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37620,7 +37608,8 @@ var TextSecureServer = (function() {
|
||||||
user : this.username,
|
user : this.username,
|
||||||
password : this.password,
|
password : this.password,
|
||||||
validateResponse: param.validateResponse,
|
validateResponse: param.validateResponse,
|
||||||
certificateAuthorities: window.config.certificateAuthorities
|
certificateAuthorities: window.config.certificateAuthorities,
|
||||||
|
timeout : param.timeout
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
var code = e.code;
|
var code = e.code;
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
|
@ -37669,7 +37658,8 @@ var TextSecureServer = (function() {
|
||||||
type : "GET",
|
type : "GET",
|
||||||
responseType: "arraybuffer",
|
responseType: "arraybuffer",
|
||||||
contentType : "application/octet-stream",
|
contentType : "application/octet-stream",
|
||||||
certificateAuthorities: window.config.certificateAuthorities
|
certificateAuthorities: window.config.certificateAuthorities,
|
||||||
|
timeout: 0
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
requestVerificationSMS: function(number) {
|
requestVerificationSMS: function(number) {
|
||||||
|
@ -37827,7 +37817,8 @@ var TextSecureServer = (function() {
|
||||||
httpType : 'GET',
|
httpType : 'GET',
|
||||||
urlParameters : '/' + id,
|
urlParameters : '/' + id,
|
||||||
responseType : 'json',
|
responseType : 'json',
|
||||||
validateResponse : {location: 'string'}
|
validateResponse : {location: 'string'},
|
||||||
|
timeout : 0
|
||||||
}).then(function(response) {
|
}).then(function(response) {
|
||||||
return ajax(response.location, {
|
return ajax(response.location, {
|
||||||
type : "GET",
|
type : "GET",
|
||||||
|
@ -37841,6 +37832,7 @@ var TextSecureServer = (function() {
|
||||||
call : 'attachment',
|
call : 'attachment',
|
||||||
httpType : 'GET',
|
httpType : 'GET',
|
||||||
responseType : 'json',
|
responseType : 'json',
|
||||||
|
timeout : 0
|
||||||
}).then(function(response) {
|
}).then(function(response) {
|
||||||
return ajax(response.location, {
|
return ajax(response.location, {
|
||||||
type : "PUT",
|
type : "PUT",
|
||||||
|
|
|
@ -24,22 +24,8 @@ var TextSecureServer = (function() {
|
||||||
return true;
|
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) {
|
function createSocket(url) {
|
||||||
var requestOptions = { ca: window.config.certificateAuthorities };
|
var requestOptions = { ca: window.config.certificateAuthorities };
|
||||||
|
|
||||||
scheduleHangWorkaround();
|
|
||||||
|
|
||||||
return new nodeWebSocket(url, null, null, null, requestOptions);
|
return new nodeWebSocket(url, null, null, null, requestOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,11 +37,14 @@ var TextSecureServer = (function() {
|
||||||
url = options.host + '/' + options.path;
|
url = options.host + '/' + options.path;
|
||||||
}
|
}
|
||||||
console.log(options.type, url);
|
console.log(options.type, url);
|
||||||
|
var timeout = typeof options.timeout !== 'undefined' ? options.timeout : 5000;
|
||||||
|
|
||||||
var fetchOptions = {
|
var fetchOptions = {
|
||||||
method: options.type,
|
method: options.type,
|
||||||
body: options.data || null,
|
body: options.data || null,
|
||||||
headers: { 'X-Signal-Agent': 'OWD' },
|
headers: { 'X-Signal-Agent': 'OWD' },
|
||||||
agent: new httpsAgent({ca: options.certificateAuthorities})
|
agent: new httpsAgent({ca: options.certificateAuthorities}),
|
||||||
|
timeout: timeout
|
||||||
};
|
};
|
||||||
|
|
||||||
if (fetchOptions.body instanceof ArrayBuffer) {
|
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');
|
console.log(options.type, url, response.status, 'Success');
|
||||||
resolve(result, response.status);
|
resolve(result, response.status);
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,7 +96,6 @@ var TextSecureServer = (function() {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
reject(HTTPError(0, e.toString(), options.stack));
|
reject(HTTPError(0, e.toString(), options.stack));
|
||||||
});
|
});
|
||||||
scheduleHangWorkaround();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +171,8 @@ var TextSecureServer = (function() {
|
||||||
user : this.username,
|
user : this.username,
|
||||||
password : this.password,
|
password : this.password,
|
||||||
validateResponse: param.validateResponse,
|
validateResponse: param.validateResponse,
|
||||||
certificateAuthorities: window.config.certificateAuthorities
|
certificateAuthorities: window.config.certificateAuthorities,
|
||||||
|
timeout : param.timeout
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
var code = e.code;
|
var code = e.code;
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
|
@ -232,7 +221,8 @@ var TextSecureServer = (function() {
|
||||||
type : "GET",
|
type : "GET",
|
||||||
responseType: "arraybuffer",
|
responseType: "arraybuffer",
|
||||||
contentType : "application/octet-stream",
|
contentType : "application/octet-stream",
|
||||||
certificateAuthorities: window.config.certificateAuthorities
|
certificateAuthorities: window.config.certificateAuthorities,
|
||||||
|
timeout: 0
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
requestVerificationSMS: function(number) {
|
requestVerificationSMS: function(number) {
|
||||||
|
@ -390,7 +380,8 @@ var TextSecureServer = (function() {
|
||||||
httpType : 'GET',
|
httpType : 'GET',
|
||||||
urlParameters : '/' + id,
|
urlParameters : '/' + id,
|
||||||
responseType : 'json',
|
responseType : 'json',
|
||||||
validateResponse : {location: 'string'}
|
validateResponse : {location: 'string'},
|
||||||
|
timeout : 0
|
||||||
}).then(function(response) {
|
}).then(function(response) {
|
||||||
return ajax(response.location, {
|
return ajax(response.location, {
|
||||||
type : "GET",
|
type : "GET",
|
||||||
|
@ -404,6 +395,7 @@ var TextSecureServer = (function() {
|
||||||
call : 'attachment',
|
call : 'attachment',
|
||||||
httpType : 'GET',
|
httpType : 'GET',
|
||||||
responseType : 'json',
|
responseType : 'json',
|
||||||
|
timeout : 0
|
||||||
}).then(function(response) {
|
}).then(function(response) {
|
||||||
return ajax(response.location, {
|
return ajax(response.location, {
|
||||||
type : "PUT",
|
type : "PUT",
|
||||||
|
|
Loading…
Reference in a new issue