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

added a graceful shutdown method, added -spawnChild mode #10

Merged
merged 12 commits into from
Sep 23, 2019

Conversation

ruesier
Copy link
Contributor

@ruesier ruesier commented Aug 24, 2019

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

Should be backwards compatible with previous versions
@googlebot
Copy link

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 @googlebot I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@ruesier
Copy link
Contributor Author

ruesier commented Aug 24, 2019

@googlebot I signed it!

@googlebot
Copy link

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.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

Copy link
Member

@tbpg tbpg left a 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 Show resolved Hide resolved
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 {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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 {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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,
Copy link
Member

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.

Copy link
Contributor Author

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 Show resolved Hide resolved
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 {
Copy link
Member

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.)

Copy link
Contributor Author

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.

Copy link
Member

@tbpg tbpg left a 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 Show resolved Hide resolved
tika/server.go Outdated Show resolved Hide resolved
tika/server.go Outdated Show resolved Hide resolved
tika/server.go Outdated Show resolved Hide resolved
tika/server.go Outdated

func (co *ChildOptions) getArgs() []string {
if co == nil {
return []string{}
Copy link
Member

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.

tika/server.go Outdated Show resolved Hide resolved
case <-ctx.Done():
}
}()
select {
Copy link
Member

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?

ruesier and others added 6 commits September 1, 2019 14:33
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]>
@ruesier
Copy link
Contributor Author

ruesier commented Sep 1, 2019

alright, enacted the changed you recommended, let me know if there is anything else I could do to pass the checks

@tbpg
Copy link
Member

tbpg commented Sep 23, 2019

@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?

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@calld
Copy link

calld commented Sep 23, 2019

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

@tbpg
Copy link
Member

tbpg commented Sep 23, 2019

Thank you!

@tbpg tbpg merged commit 92d0506 into google:master Sep 23, 2019
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.

4 participants