-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Allow loading grpc/errors.rb before grpc.rb #19893
Conversation
I'm thinking we can still save the benefits of this change, but without adding the second clone module. Is it possible to just move the status code definitions in the C extension to this pure ruby file, but keep all of the constants under the same module? I.e., I'm thinking we could delete this function: https://github.com/grpc/grpc/blob/master/src/ruby/ext/grpc/rb_grpc.c#L158, and then have the new ruby file put the codes under Also, can we add a test script to illustrate this; we could probably have a small test script under |
Funny enough, using
Yes, that should be possible. I wanted this PR to be as additive as possible, so I didn't want to mess with that existing code. Would you like me to make that change in this PR? |
Yes please, I'd prefer to do this one as an atomic change. |
@apolcyn I think i fixed the copyright problem. Can you restart Kokoro? |
Are those Kokoro failures due to the changes made in this PR? |
@apolcyn The tools scripts that failed on Kokoro pass for me locally. Do you understand why it failed? Should I rebase this PR on latest master? |
@@ -0,0 +1,135 @@ | |||
# Copyright 2015 gRPC authors. |
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.
Now that I've fixed the copyright failure, should these new files all use 2019?
Those errors look unrelated to this change, no need ot rebase |
@blowmage before merging, can you please squash down the commits into one, e.g. with a |
47bd959
to
b132c34
Compare
Squashed. |
C/C++ macos: #19819 |
@apolcyn Thanks for accepting! This will be released in 1.24.0, right? It isn't going to make it for the upcoming 1.23.0 release? |
Yes, this will be in the 1.24.0 release. And right, the 1.23.0 branch has been cut (we don't tend to backport larger changes like this). |
K, I was playing with this some more and it looks like |
As you know, the Ruby gem loads the compiled gRPC library and initializes all system resources when the following is called in a Ruby file:
Once the compiled gRPC library is loaded the Ruby process cannot be forked, so it is very common for Ruby apps to delay requiring GRPC until right before it is needed. (See #8798) However, it would be very beneficial for Ruby apps to be able to reference some GRPC code structures before the compiled gRPC library is loaded. For instance, it would be beneficial to be able to register error handlers.
This PR makes a couple small changes. First, it removes the
require_relative './grpc'
fromgrpc/errors.rb
, allowing the error classes to be loaded before the compiled gRPC library. Now thegrpc/errors.rb
file behaves the same as thegrpc/logconfig.rb
file, whererequire 'grpc/logconfig'
can be called beforerequire 'grpc'
which loads the compiled gRPC library.Second, it adds the file
grpc/status_codes.rb
that definesGPRC::StatusCodes
to the gem.GPRC::StatusCodes
is the same structure asGPRC::Core::StatusCodes
, but the latter is defined in the compiled gRPC library, and therefore can't be used. SoGPRC::StatusCodes
has been added that defines the same values, with documentation, so it can also be documented as part of the public API. Thegrpc/errors.rb
file now depends on this newgrpc/status_codes.rb
file.These changes allow errors to be loaded before the compiled gRPC library and is backwards compatible to previous releases.