better command timeouts

This commit is contained in:
sebv
2015-09-06 04:56:33 +08:00
parent c62bcad293
commit bb7ecb96cf
2 changed files with 15 additions and 9 deletions
+13 -2
View File
@@ -22,10 +22,21 @@ helpers.clearNewCommandTimeout = function () {
}
};
helpers.startNewCommandTimeout = function (onCommandTimeout) {
helpers.startNewCommandTimeout = function (cmd) {
// make sure there are no rogue timeouts
this.clearNewCommandTimeout();
// if command timeout is 0, it is disabled
if(!this.newCommandTimeoutMs) return;
// TODO: replace setTimeout by CancellableDelay
this.noCommandTimer = setTimeout(() => {
B.resolve(onCommandTimeout()).done();
let onCommand = async () => {
log.warn(`Shutting down because we waited ` +
`${this.newCommandTimeoutMs / 1000} seconds for a command`);
await this.startUnexpectedShutdown(new Error(`Command ${cmd} timed out!`));
};
B.resolve(onCommand()).done();
}, this.newCommandTimeoutMs);
};
+2 -7
View File
@@ -163,14 +163,9 @@ class BaseDriver extends MobileJsonWireProtocol {
// automatic session deletion in this.onCommandTimeout. Of course we don't
// want to trigger the timer when the user is shutting down the session
// intentionally
if (this.newCommandTimeoutMs && cmd !== 'deleteSession') {
if (cmd !== 'deleteSession') {
// reseting existing timeout
this.clearNewCommandTimeout();
this.startNewCommandTimeout(async () => {
log.warn(`Shutting down because we waited ` +
`${this.newCommandTimeoutMs / 1000} seconds for a command`);
await this.startUnexpectedShutdown(new Error(`Command ${cmd} timed out!`));
});
this.startNewCommandTimeout(cmd);
}
return res;