[common] revert started flag when service already stopped#2326
[common] revert started flag when service already stopped#2326
Conversation
also, return ErrNotStarted when trying to stop a not-running service
| if atomic.LoadUint32(&bs.stopped) == 1 { | ||
| bs.Logger.Error(fmt.Sprintf("Not starting %v -- already stopped", bs.name), "impl", bs.impl) | ||
| // revert flag | ||
| atomic.StoreUint32(&bs.started, 0) |
There was a problem hiding this comment.
I'm confused as to why we have separate started and stopped flags. Shouldn't started = !stopped? It seems like doing that would simplify alot of this code, is that approach not safe with concurrency?
There was a problem hiding this comment.
There was a discussion about simplifying Service and @jaekwon made a PR tendermint/tmlibs#114. Not sure why we did not merge it.
|
What motivated this ? |
We should not panic if somebody's trying to Stop a not-started WSClient. |
|
This PR seems good to me, but I'd prefer if we removed |
|
How about we merge this and bring tendermint/tmlibs#114 in? |
ValarDragon
left a comment
There was a problem hiding this comment.
Lgtm, lets go with your suggestion and bring in the relevant tmlibs PR
|
I think this is fine for now. If we want to allow for services to restart, it may be better to require an explicit "restarting". If in the future we know that (a) we want the ability for services to be started and stopped and started again and (b) we don't want to require explicit "restart" calls, then it would make sense to merge start/stop, but I prefer the way things are for the reasons above. |
also, return ErrNotStarted when trying to stop a not-running service