Ruby: refactor init/shutdown logic to avoid using atexit; fix windows#17997
Merged
apolcyn merged 1 commit intogrpc:masterfrom Feb 11, 2019
Merged
Ruby: refactor init/shutdown logic to avoid using atexit; fix windows#17997apolcyn merged 1 commit intogrpc:masterfrom
apolcyn merged 1 commit intogrpc:masterfrom
Conversation
9a04893 to
5c85f5a
Compare
nicolasnoble
approved these changes
Feb 11, 2019
Contributor
Author
|
cloud to prod interop test failure: #18004 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #17799
It looks like grpc-ruby on Windows is running into the issue described in this interesting blog post. Currently, in the ruby extension on Windows, Ruby loads the grpc-ruby extension library, and that library sets up an
atexithandler to callgrpc_rb_shutdown, which then calls into the C-core dll. Apparently, on Windows each dll has it's own separateatexitstack, and the order of process shutdown goes roughly as follows:atexithandlers called as a part of their unloadingSo in grpc-ruby extension's
atexithandler, it callsgrpc_shutdownand proceeds to try to await timer threads to signal their completions, but the timer threads are no longer running, and so we hang.Overall it seems
atexitis dubious. So this PR refactors thegrpc_init/grpc_shutdownlogic as follows:grpc_ruby_initgrpc_ruby_shutdowngrpc_ruby_init/grpc_ruby_shutdownpair.Note that we no longer schedule grpc init and shutdown only once, and I've deleted the comment on why that's needed. But I believe the described scenario would have been broken for a long time anyways :), because there are ruby-level grpc background threads for which we don't make any attempt to cleanly reset their state at the end of a ruby VM's lifetime.