-
Notifications
You must be signed in to change notification settings - Fork 134
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 a Shutdown Method to sdk.Handler #124
base: main
Are you sure you want to change the base?
Conversation
A library should not setup signal handlers. |
Or perhaps by having it return a closer on "Serve" |
Right, something like that was my first thought but I tried to fix the behaviour I was seeing without modifying the API. How about adding I am going to see what both options look like. |
So. I changed the Handler#Serve method to run http.Server#Serve in a go routine. It returns a Closer implementation which shuts down the http.Server using its Shutdown method. The serve{TCP,Unix,Windows} methods wrap the Closer returned from Serve to additionally delete the spec file. The resulting Closer is returned to the user to enable closing the Server in response to, e.g., OS signals. |
sdk/handler.go
Outdated
|
||
func (s serverCloser) Close() error { | ||
// Wait at most 10 seconds for the server.Shutdown method to return | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
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.
Maybe make the 10s configurable? 10s in some use-cases is quite long
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.
Makes sense, I will see about adding that somehow.
There is a lot more work to be done, many other parts of the repository use the functions that I modified. I am still undecided whether I should change the return type or add new functions for async listening. The latter would not break the existing callsites obviously. |
So, I will say, you are passing in the listener into the I think it may be best, in terms of adding a proper shutdown, to add a These I honestly don't know why we did anything in this library other than generate an |
- Add a Shutdown method - Implement ServeXYZ methods on *Handler, adjust plugin Handlers
8c9a2f3
to
a0ff4b1
Compare
I followed your advice and added a Shutdown method to the sdk.Handler. Seems a lot cleaner though the user has to write more code now. I am certainly not a Go expert but the test suite passes and the volume plugin I am writing works fine. What do you think? Anything I can improve? |
I'm hitting the same problem of not being able to cleanly terminate driver handlers ... which is especially bad for especially end-to-end testing. Is there anything why this PR should not be moved forward again? Or would there be a chance for a new PR in case we can't breathe life into this one again, with the following design: turn sdk.Handler into a struct type that stores the current http.server (concurrency safe) and implements new Close and Shutdown pointer receivers? |
... by shutting down the http.Server using the proper method.
This is a WIP and I am very much open to suggestions. We might think about exposing the
http.Server
somehow so a plugin author can handle shutting it down.This refers to #123