-
Notifications
You must be signed in to change notification settings - Fork 40
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
added a graceful shutdown method, added -spawnChild mode #10
Conversation
Should be backwards compatible with previous versions
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
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.
Thanks!
tika/server.go
Outdated
@@ -67,14 +77,35 @@ func NewServer(jar, port string) (*Server, error) { | |||
return s, nil | |||
} | |||
|
|||
// ChildMode sets up the server to use the -spawnChild option | |||
// must be called before starting the server | |||
func (s *Server) ChildMode(maxfiles, taskpulse, tasktimeout, pingpulse, pingtimeout int) error { |
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.
Please switch these args to camelCase. https://github.com/golang/go/wiki/CodeReviewComments#mixed-caps
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.
will do
case <-ctx.Done(): | ||
} | ||
}() | ||
select { |
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.
Could this all be a single select
statement?
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.
Your right, I'll change this, Was originally thinking that I was going to need two threads to handle the Signalling and error handling.
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.
Actually no, went to implement this change and realized that s.cmd.Wait() runs synchronously. So s.cmd.Wait() can't be a case in a select statement, I need to wrap it inside it's own go routine to make it asynchronous with the context.Context.
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.
Ah. That definitely makes sense. Mind adding a comment to Stop
referencing Shutdown
?
@@ -123,6 +154,32 @@ func (s *Server) Stop() error { | |||
return nil | |||
} | |||
|
|||
// Shutdown attempts to close the server gracefully before using SIGKILL, |
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.
Should we change the behavior of Stop
and add a context.Context
argument? If someone wants to kill immediately, they can pass a context.Context
that is Done
.
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.
We can but that would make this update not backwards compatible. I added a Shutdown Method in order to not conflict with Stop. Also the golang documentation, on sending signals in the "os" package, warns that Sending Interrupt is not implemented in Windows. (https://golang.org/pkg/os/#Process.Signal). So currently Shutdown would not be advised in a Windows environment.
Yes, passing a context.Context that is Done would currently send a SIGINT signal followed immediately by a SIGKILL. That was the intended behavior of Shutdown.
tika/server.go
Outdated
@@ -67,14 +77,35 @@ func NewServer(jar, port string) (*Server, error) { | |||
return s, nil | |||
} | |||
|
|||
// ChildMode sets up the server to use the -spawnChild option | |||
// must be called before starting the server | |||
func (s *Server) ChildMode(maxfiles, taskpulse, tasktimeout, pingpulse, pingtimeout int) error { |
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.
Are all of these arguments required? Will you update the function comment either way? (And handle missing args as needed.)
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.
how about making the childOptions struct public (-> ChildOptions), then make the parameter to the ChildMode just a pointer to a ChildOptions.
Co-Authored-By: Tyler Bui-Palsulich <[email protected]>
Co-Authored-By: Tyler Bui-Palsulich <[email protected]>
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.
A few other small comments then good to go! Thank you!
tika/server.go
Outdated
|
||
func (co *ChildOptions) getArgs() []string { | ||
if co == nil { | ||
return []string{} |
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.
In general, should avoid making a distinction between nil
and an empty slice. So, it's most common to just return nil
.
case <-ctx.Done(): | ||
} | ||
}() | ||
select { |
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.
Ah. That definitely makes sense. Mind adding a comment to Stop
referencing Shutdown
?
Co-Authored-By: Tyler Bui-Palsulich <[email protected]>
Co-Authored-By: Tyler Bui-Palsulich <[email protected]>
Co-Authored-By: Tyler Bui-Palsulich <[email protected]>
Co-Authored-By: Tyler Bui-Palsulich <[email protected]>
Co-Authored-By: Tyler Bui-Palsulich <[email protected]>
alright, enacted the changed you recommended, let me know if there is anything else I could do to pass the checks |
@ruesier So sorry for the delay! Was on vacation for a week and am just getting around to this. I fixed the issue causing the tests to fail. So, if you merge the latest changes from master, it should all work. Looks like you may have used two emails for the commits in this PR, and one of them (@calld) doesn't have a CLA on file. Would you mind changing the author emails to be consistent? |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
alright updated commit history to correctly identify me so that googlebot recognizes that I have a valid CLA. and synced my fork with current version of repo. I believe it is ready to go |
Thank you! |
Should be backwards compatible with previous versions of package
Running with the spawnChild option makes Tika Server Robust to OOMs, Infinite Loops and Memory Leaks: https://cwiki.apache.org/confluence/display/tika/TikaJAXRS#TikaJAXRS-MakingTikaServerRobusttoOOMs,InfiniteLoopsandMemoryLeaks