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

Ability to stop cmux listeners #39

Open
chandradeepak opened this issue Dec 12, 2016 · 4 comments
Open

Ability to stop cmux listeners #39

chandradeepak opened this issue Dec 12, 2016 · 4 comments

Comments

@chandradeepak
Copy link

Feature request:
Right now once we start cmux.Serve is there a way to clean shut down the cmux listeners and all its internal listeners it starts. So that way during the whole service shut down we call cmux.Stop and make sure all the listeners are shut down clean.

@chandradeepak
Copy link
Author

may be some thing like a Stop method which not only does the m.root.Close() and also make sure it closes other connections .

`defer func() {
close(m.donec)
wg.Wait()

	for _, sl := range m.sls {
		close(sl.l.connc)
		// Drain the connections enqueued for the listener.
		for c := range sl.l.connc {
			_ = c.Close()
		}
	}
}()`

Most of it is there in defer func of Serve.

so we need to make sure it doesn't happen at two places .

@shabbyrobe
Copy link

I don't see a neat way to close cmux down at all. I could be misreading the docs but even though it says ErrListenerClosed is supposed to be returned, I get a net.OpError instead that says "use of closed network connection".

@wood-jp
Copy link

wood-jp commented Aug 16, 2018

Any progress on this? I'm using cmux to share HTTP/REST and gRPC on the same port as I slowly transition from the former to the later. Both of those have graceful shutdown options, but I find that cmux.Serve() does not throw a clear error (I get the same thing as @shabbyrobe), making my life difficult.

@puellanivis
Copy link

So, while a “graceful shutdown” is in part available through PR-69 to call a Close() function, the unexported muxListener type that wraps the net.Listener that is the actual net.Listener set during the cmux.New(), does not implement its own Close() function, so when either a gRPC or HTTP server is told to gracefully shutdown, it will passthrough close the main net.Listener port, breaking cmux.CMux.Serve and any other service also setup.

Ideally, the cmux.CMux.Close() would handle closing the actual net.Listener (so new connections are rejected) and then the Close() from each of the muxListener children will only close their own individual acceptance channels, which will then allow all pending Accept to be drained, and then the server shutdown once all the outstanding handlers finish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants