1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 19:42:01 +02:00

Fix unexpected minicap death during start causing a TimeoutError, causing the licecycle to end unnecessarily. Now it will just try again like it should have from the start.

This commit is contained in:
Simo Kinnunen 2015-04-27 11:48:42 +09:00
parent 5d9b77a76a
commit 688ddda713
2 changed files with 52 additions and 27 deletions

View file

@ -37,6 +37,7 @@ module.exports = syrup.serial()
this.frameConfig = config
this.readable = false
this.needsReadable = false
this.starter = Promise.resolve(true)
}
util.inherits(FrameProducer, EventEmitter)
@ -47,6 +48,10 @@ module.exports = syrup.serial()
FrameProducer.STATE_STOPPING = 4
FrameProducer.prototype._ensureState = function() {
if (this.desiredState.empty()) {
return
}
switch (this.runningState) {
case FrameProducer.STATE_STARTING:
case FrameProducer.STATE_STOPPING:
@ -55,7 +60,7 @@ module.exports = syrup.serial()
case FrameProducer.STATE_STOPPED:
if (this.desiredState.next() === FrameProducer.STATE_STARTED) {
this.runningState = FrameProducer.STATE_STARTING
this._startService().bind(this)
this.starter = this._startService().bind(this)
.then(function(out) {
this.output = new RiskyStream(out)
.on('unexpectedEnd', this._outputEnded.bind(this))
@ -78,42 +83,31 @@ module.exports = syrup.serial()
this.runningState = FrameProducer.STATE_STARTED
this.emit('start')
})
.catch(Promise.CancellationError, function() {
return this._stop()
})
.catch(function(err) {
this.runningState = FrameProducer.STATE_STOPPED
this.emit('error', err)
return this._stop().finally(function() {
this.emit('error', err)
})
})
.finally(function() {
this._ensureState()
})
}
else {
setImmediate(this._ensureState.bind(this))
}
break
case FrameProducer.STATE_STARTED:
if (this.desiredState.next() === FrameProducer.STATE_STOPPED) {
this.runningState = FrameProducer.STATE_STOPPING
this._disconnectService(this.socket).bind(this)
.timeout(2000)
.then(function() {
return this._stopService(this.output).timeout(10000)
})
.then(function() {
this.runningState = FrameProducer.STATE_STOPPED
this.emit('stop')
})
.catch(function(err) {
// In practice we _should_ never get here due to _stopService()
// being quite aggressive. But if we do, well... assume it
// stopped anyway for now.
this.runningState = FrameProducer.STATE_STOPPED
this.emit('error', err)
this.emit('stop')
})
.finally(function() {
this.output = null
this.socket = null
this.banner = null
this.parser = null
this._ensureState()
})
this._stop().finally(function() {
this._ensureState()
})
}
else {
setImmediate(this._ensureState.bind(this))
}
break
}
@ -135,6 +129,7 @@ module.exports = syrup.serial()
switch (this.runningState) {
case FrameProducer.STATE_STARTED:
case FrameProducer.STATE_STARTING:
this.starter.cancel()
this.desiredState.push(FrameProducer.STATE_STOPPED)
this.desiredState.push(FrameProducer.STATE_STARTED)
this._ensureState()
@ -248,6 +243,32 @@ module.exports = syrup.serial()
return tryConnect(5, 100)
}
FrameProducer.prototype._stop = function() {
return this._disconnectService(this.socket).bind(this)
.timeout(2000)
.then(function() {
return this._stopService(this.output).timeout(10000)
})
.then(function() {
this.runningState = FrameProducer.STATE_STOPPED
this.emit('stop')
})
.catch(function(err) {
// In practice we _should_ never get here due to _stopService()
// being quite aggressive. But if we do, well... assume it
// stopped anyway for now.
this.runningState = FrameProducer.STATE_STOPPED
this.emit('error', err)
this.emit('stop')
})
.finally(function() {
this.output = null
this.socket = null
this.banner = null
this.parser = null
})
}
FrameProducer.prototype._disconnectService = function(socket) {
log.info('Disconnecting from minicap service')

View file

@ -6,6 +6,10 @@ StateQueue.prototype.next = function() {
return this.queue.shift()
}
StateQueue.prototype.empty = function() {
return this.queue.length === 0
}
StateQueue.prototype.push = function(state) {
var found = false