-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[common] revert started flag when service already stopped #2326
Conversation
also, return ErrNotStarted when trying to stop a not-running service
@@ -124,6 +131,8 @@ func (bs *BaseService) Start() error { | |||
if atomic.CompareAndSwapUint32(&bs.started, 0, 1) { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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