refactor
fixed close gate problem
switched shutdown to be executed first, when state transition to finished, failure or canceled
fixed close gate problem
switched shutdown to be executed first, when state transition to finished, failure or canceled