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

Add CMux.Close() to shutdown server #69

Merged
merged 6 commits into from
Jan 14, 2021
Merged

Conversation

jan25
Copy link
Contributor

@jan25 jan25 commented Jun 14, 2019

We don't have a nice way to close CMux server. This PR adds a Close method that tries to gracefully stop cmux server.

Related issue: #39

@sword-jin
Copy link

@jan25
wow,why not author merge? ci wrong?

@jan25
Copy link
Contributor Author

jan25 commented Feb 28, 2020

@rrylee Let me fix the CI and do few tests when i get a chance. Also i don't have Merge rights, so owners of this repo suggestions on this PR? @soheilhy

@Krithika3
Copy link

@jan25 is there a chance this can be merged?

@jan25
Copy link
Contributor Author

jan25 commented May 21, 2020

Hi @Krithika3. I can only try to finish up this PR. I will need maintainers help to review and merge as i don't have the rights. Looks like the last release was more than 2yrs ago, so not sure if this will ever be merged.

jan25 added 2 commits May 21, 2020 08:19
Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
@stoksc
Copy link

stoksc commented Oct 20, 2020

@soheilhy Any way to get this merged? https://github.com/grpc/grpc-go expects calls to Accept to unblock whenever the listeners its using are closed, but since cmux doesn't it Stop/GracefulStop block forever. (or something like, reading all this code for the first time and my head hurts, sorry lol)

@soheilhy
Copy link
Owner

Hey sorry for the delay. @jan25 can you please add a test for this? otherwise, looks ok.

gcf-merge-on-green bot pushed a commit to googleapis/gapic-showcase that referenced this pull request Oct 22, 2020
This PR uses the cmux package to expose a single external port that selects incoming connections to route to the gRPC endpoint or the REST endpoint.
(ref: https://medium.com/@drgarcia1986/listen-grpc-and-http-requests-on-the-same-port-263c40cb45ff and https://github.com/soheilhy/cmux)

I define an Endpoint interface wrapping both the gRPC and the REST endpoints, as well as the cmux multiplexer that does the redirection. This infrastructure will also allow future endpoints to be easily added when we need them.

This also sets up the infrastructure for graceful shutdown upon receipt of a signal, though we are waiting for a PR in the cmux dependency for that to work fully. (The issue is described in soheilhy/cmux#69 (comment).)

Implementation/review notes:
- the gRPC server set-up code is now in `cmd/gapic-showcase/endpoint.go`. It is split between setting up the server and running it.
- the REST server (also in `endpoint.go`) is currently a stub that simply responds to `/hello` requests. It will be expanded with auto-generated handlers.
@jan25
Copy link
Contributor Author

jan25 commented Oct 25, 2020

@soheilhy thanks. I'll finalize this PR soon

Copy link

@aruiz14 aruiz14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not a maintainer but just happened to stumble upon this PR, and spotted a possible bug while taking a look at the changes.
BTW thanks for the PR!

cmux.go Outdated Show resolved Hide resolved
cmux.go Show resolved Hide resolved
@vchudnov-g
Copy link

@jan25 This PR will be very useful! Do you have an ETA for getting it finished? Thanks for your work on this!

Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
@jan25
Copy link
Contributor Author

jan25 commented Jan 6, 2021

Sorry for late response. I have to fix/add tests, i'll spend some time this week to finish.

Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
@jan25 jan25 changed the title WIP: add cmux.Close() function Add CMux.Close() to shutdown server Jan 14, 2021
@jan25
Copy link
Contributor Author

jan25 commented Jan 14, 2021

I've added tests and fixed other breaking tests. @soheilhy could you please review?

@soheilhy
Copy link
Owner

Looks great. Thank you for adding the tests!

@soheilhy soheilhy merged commit cdd3331 into soheilhy:master Jan 14, 2021
@jan25 jan25 deleted the cmux-close branch January 15, 2021 09:53
Copy link

@puellanivis puellanivis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 Imagine my surprise, when I come back to this PR and see that I never sent out these comments.

@@ -93,6 +97,8 @@ type CMux interface {
// Serve starts multiplexing the listener. Serve blocks and perhaps
// should be invoked concurrently within a go routine.
Serve() error
// Closes cmux server and stops accepting any connections on listener
Close()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try and use Close() error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error can inform user about multiple Close() calls. Are there other cases when error can be useful?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The principle interest is in satisfying the interface { Close() error } (i.e. the io.Closer interface) more than anything else.

For instance, net.Listener for instance implements io.Closer.

But it’s definitely not anything critical, just expected that Close() returns an error.

sls []matchersListener
readTimeout time.Duration
donec chan struct{}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to put things that are protected by a mutex underneath the mutex.

@zhangqibupt
Copy link

So glad to see this great prgress, do we have a plan to draft a new release?

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.

9 participants