-
Notifications
You must be signed in to change notification settings - Fork 2
Fix the graceful shutdown #272
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
Conversation
968fe4e to
6855086
Compare
56aaa8f to
b45b1cb
Compare
|
Some things I've noticed:
|
Changed: After logging Fatal and returning nil or err, no matter what exactly the ocis anyway must die. The
The constructors return nil if no server is expected or die if misconfigured. |
| func (s *Server) Stop() error { | ||
| s.cleanupServices() | ||
| s.s.Stop() | ||
| s.cleanupServices() |
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.
@jvillafanez I assumed that we should stop the Listen first and then clean the services. Could you check if it makes sense?
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.
As far as I know, this Stop method will be call by a secondary thread because the main one will be running the service. Once we call s.s.Stop(), the main thread will keep going, so there is a risk that the app finishes without having run the s.cleanupServices() (or maybe it runs partially for some services until the app closes).
Maybe I'm wrong, there are too many Stop methods and it's hard to know which one we're calling here.
kobergj
left a comment
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.
Just small question. Code looks good 👍
cmd/revad/runtime/drivenserver.go
Outdated
| // NewDrivenHTTPServerWithOptions runs a revad server w/o watcher with the given config file and options. | ||
| // Use it in cases where you want to run a revad server without the need for a watcher and the os signal handling as a part of another runtime. | ||
| // Returns nil if no http server is configured in the config file. | ||
| // Throws a fatal error if the http server cannot be created. |
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.
Just saying that throwing isn't logging.
The code is fine if we consider that the fatal log won't happen in practice. If something is wrong, it should be fixed during development.
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.
Just saying that throwing isn't logging.
Why? I can rephrase it, the meaning remains the same. Both log.Fatal() and options.Logger.Fatal() will print a message and then call an os.Exit(1).
I can change // Throws a fatal error if the http server cannot be created. to // Call a fatal error if the http server cannot be created.
The only way wrong is if we call the logger and then exit(1) because there is a very big chance that we never see this log.
options.Logger.Error().Err(err).Msg("error runnig server")
w.Exit(1)
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.
It's just a wording change in the comment. Logs a fatal error seems more clear to me.
Throw is a keyword in other languages such as Java and PHP, and it have a very specific meaning. Even if we consider Go language, it might be confusing specially when the function doesn't return (or "throw") an error that we could handle upwards.
As said, the code is fine, it's just the wording.
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.
ok. updated.
|
I assume we don't want to be too strict with the |
| // Use it in cases where you want to run a revad server without the need for a watcher and the os signal handling as a part of another runtime. | ||
| // Returns nil if no http server is configured in the config file. | ||
| // The GracefulShutdownTimeout set to default 20 seconds and can be overridden in the core config. | ||
| // Logging a fatal error and exit with code 1 if the http server cannot be created. |
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.
The "exit with code 1" is misleading because the function never does it. As it is written, it seems there is a os.Exit(-1) call hidden somewhere inside this function, but it isn't the case.
If, as a result of this function returning nil, the main app decides to exit with code 1, that's fine, but it's something this function doesn't need to care about. Whatever the caller does with the result of this function isn't this function's business.
Added the comments. |
Added the reva HTTP/GRPC servers constructor w/o the watcher and the os signal handling to make it driven by the ocis runtime.
owncloud/ocis#11170