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

sdks/cpp should not include generated C++ code for protos it doesn't own #906

Closed
devjgm opened this issue Jul 13, 2019 · 12 comments
Closed
Labels
help wanted We would love help on these issues. Please come help us! kind/bug These are bugs. obsolete wontfix Sorry, but we're not going to do that.

Comments

@devjgm
Copy link
Contributor

devjgm commented Jul 13, 2019

What happened:

The sdks/cpp package contains protoc-generated files for protos that this project does not own. For example, annotations.pb.h and http.pb.h (https://github.com/googleforgames/agones/tree/master/sdks/cpp/include/google/api). The corresponding .cc files are included as well.

This is a problem because it will lead to ODR (One Definition Rule) violations as soon as a customer uses those same protos from some other location (including the proto's real location). ODR violations result in Undefined Behavior.

The practical problem is that customers should not use the Agones C++ library with any other code. This probably makes the agones library significantly less useful, which is why I'm reporting this as a "bug".

What you expected to happen:

To avoid ODR problems in C++, every source file (and header) should have one single authoritative location where everyone gets it from, and one official "build" rule (this could be a bazel BUILD file and/or a CMakeLists.txt file). This ensures that everyone who uses a particular source file are using the same version of the file and it's compiled in the same way.

For these particular files (the ones that this project does not own), you should fetch them from and compile them using the cmake rules at https://github.com/googleapis/cpp-cmakefiles

How to reproduce it (as minimally and precisely as possible):

Look at https://github.com/googleforgames/agones/tree/master/sdks/cpp/include/google/api

Anything else we need to know?:

This is one of those problems that will appear to work right now. It will appear as if there's no problem. The problem will only show up with a customer uses the Agones C++ library with any other library that uses one of these protos. And even then, it's not clear how the problem will manifest itself -- it's "undefined behavior". But we hope that the problem is just a crash :-)

Note: I don't know what version this library is, but if it's something like "alpha", then I don't think this issue is urgent. However, I would suggest that this is a show-stopper issue for a 1.0 or "GA" type release.

Environment:

  • Agones version: all
  • Kubernetes version (use kubectl version): all
  • Cloud provider or hardware configuration: alll
  • Install method (yaml/helm): all
  • Troubleshooting guide log(s): all
  • Others:
@devjgm devjgm added the kind/bug These are bugs. label Jul 13, 2019
@markmandel
Copy link
Member

markmandel commented Jul 13, 2019

So from my perspective, nobody else should ever be using the proto and using the SDK at the same time. In an ideal world, the user has no idea it's even grpc.

Is there a circumstance in which you can see the user use both?

@devjgm
Copy link
Contributor Author

devjgm commented Jul 13, 2019

You're correct that users may not know this is grpc. The problem is that this project is including the source for classes that it doesn't own.

For example, Agones includes https://github.com/googleforgames/agones/blob/master/sdks/cpp/include/google/api/http.pb.h, that is the google::api::Http class (and friends). So any user who links with Agones will also be getting a definition of google::api::Http.

However, the real owner of that class is in this project: https://github.com/googleapis/googleapis/blob/master/google/api/http.proto. So if anyone wants to use google::api::Http, they will include and link with the real location.

Now the problem is if anyone links in both libraries at the same time. Since that class will be defined multiple times, that's the violation of the One Definition Rule (ODR).

This issue can definitely happen, and indeed, I think it's fairly likely since "Http" and "Annotation" are commonly used classes.

The way to avoid ODR problems is that every symbol must come from exactly one source.

@markmandel
Copy link
Member

Ah yes, that's an excellent point. That being said, given that the http elements are only used server side - if we can make a strategy to remove them for the client side SDK, would that solve the problem?

@devjgm
Copy link
Contributor Author

devjgm commented Jul 13, 2019

Yup! I think that'd even be the ideal solution, because it would simplify the client-side SDK as well.

@dsazonoff
Copy link
Contributor

In #803 we introduced a full build of proto/grpc. So now it is possible to generate code with cmake commands like protobuf_generate_cpp and grpc_generate_cpp. And we can get rid of gen.sh which doesn't work on windows.

@markmandel
Copy link
Member

gen.sh is important because its part of our overall SDK toolkit. C++ can't be a unique snowflake. The development tools already rely on WSL for windows, so I don't think that is an issue.

The next million dollar question is what's the best way of getting rid of the server code from the generated gRPC code? (I've not had time to dig into it yet)

@dsazonoff
Copy link
Contributor

gen.sh for C++ SDK may be empty, because it's logic will be moved to cmake

@markmandel markmandel added good first issue These are great first issues. If you are looking for a place to start, start here! help wanted We would love help on these issues. Please come help us! labels Sep 25, 2019
@markmandel markmandel removed the good first issue These are great first issues. If you are looking for a place to start, start here! label Oct 27, 2022
@github-actions
Copy link

'This issue is marked as Stale due to inactivity for more than 30 days. To avoid being marked as 'stale' please add 'awaiting-maintainer' label or add a comment. Thank you for your contributions '

@github-actions github-actions bot added the stale Pending closure unless there is a strong objection. label Apr 15, 2023
@github-actions github-actions bot closed this as completed May 1, 2023
@markmandel
Copy link
Member

Reopening - looks like a bug in the bot. Should still be stale though.

@markmandel markmandel reopened this May 1, 2023
@github-actions github-actions bot removed the stale Pending closure unless there is a strong objection. label May 15, 2023
@github-actions
Copy link

'This issue is marked as Stale due to inactivity for more than 30 days. To avoid being marked as 'stale' please add 'awaiting-maintainer' label or add a comment. Thank you for your contributions '

@github-actions github-actions bot added the stale Pending closure unless there is a strong objection. label Jun 15, 2023
@github-actions
Copy link

github-actions bot commented Aug 1, 2023

This issue is marked as obsolete due to inactivity for last 60 days. To avoid issue getting closed in next 30 days, please add a comment or add 'awaiting-maintainer' label. Thank you for your contributions

@github-actions github-actions bot added obsolete and removed stale Pending closure unless there is a strong objection. labels Aug 1, 2023
@github-actions github-actions bot added the wontfix Sorry, but we're not going to do that. label Sep 1, 2023
@github-actions
Copy link

github-actions bot commented Sep 1, 2023

We are closing this as there was no activity in this issue for last 90 days. Please reopen if you’d like to discuss anything further.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted We would love help on these issues. Please come help us! kind/bug These are bugs. obsolete wontfix Sorry, but we're not going to do that.
Projects
None yet
Development

No branches or pull requests

3 participants