Skip to content
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

Merged
merged 1 commit into from
Sep 12, 2018

Conversation

melekes
Copy link
Contributor

@melekes melekes commented Sep 4, 2018

also, return ErrNotStarted when trying to stop a not-running service

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)
Copy link
Contributor

@ValarDragon ValarDragon Sep 4, 2018

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?

Copy link
Contributor Author

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.

@ebuchman
Copy link
Contributor

ebuchman commented Sep 4, 2018

What motivated this ?

@melekes
Copy link
Contributor Author

melekes commented Sep 5, 2018

#2258

func(c *rpcClient.WSClient) error {
		if c.IsRunning() {
			c.Stop() // panics on close c.ResponsesCh when not started (=nil)
		}

We should not panic if somebody's trying to Stop a not-started WSClient.

@ValarDragon
Copy link
Contributor

This PR seems good to me, but I'd prefer if we removedstarted and stopped and just had running.

@melekes
Copy link
Contributor Author

melekes commented Sep 5, 2018

How about we merge this and bring tendermint/tmlibs#114 in?

Copy link
Contributor

@ValarDragon ValarDragon left a 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

@jaekwon
Copy link
Contributor

jaekwon commented Sep 6, 2018

I think this is fine for now.
The reason why it's still split is to consider an API for restarting services... restarting may require different semantics than starting. Currently these services are run-once-only, so you can't restart a stopped process, and that may be what we want ultimately, and even if not, it's better to have a restricted API and to expand it further. Given the way we use services currently (that there is no restart-ability), we may end up masking bugs by allowing them to be restarted after being stopped.

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.

@ebuchman ebuchman merged commit e3e3c13 into develop Sep 12, 2018
@ebuchman ebuchman deleted the anton/service branch September 12, 2018 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants