There is a race in this stop function, which can cause panic. 
We need to make sure we check the state and set the state in a transaction. Or we might end up with a double close, which will cause panic.