-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(grpc): fix segfault with grpc.aio streaming responses [backport 1…
….20] (#9276) Backport 5897cab from #9233 to 1.20. This PR fixes a few issues with the grpc aio integration. Most notably, the integration was causing segfaults when wrapping async stream responses, most likely since these spans were never being finished. This issue was uncovered when customers upgraded their google-api-core dependencies to 2.17.0; with this upgrade, the package changed many grpc calls to use async streaming. In addition to fixing the segfault, this PR also fixes the Pin object to be correctly placed on the grpcio module. Fixes #9139 ## Checklist - [x] Change(s) are motivated and described in the PR description - [x] Testing strategy is described if automated tests are not included in the PR - [x] Risks are described (performance impact, potential for breakage, maintainability) - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed or label `changelog/no-changelog` is set - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)) - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) - [x] If this PR changes the public interface, I've notified `@DataDog/apm-tees`. ## Reviewer Checklist - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) --------- Co-authored-by: Emmett Butler <[email protected]>
- Loading branch information
1 parent
7a0e539
commit a979c73
Showing
9 changed files
with
425 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ MySQL | |
OpenTracing | ||
Runtimes | ||
SpanContext | ||
aio | ||
aiobotocore | ||
aiohttp | ||
aiomysql | ||
|
4 changes: 4 additions & 0 deletions
4
releasenotes/notes/fix-grpc-bug-caused-by-google-api-core-upgrade-abbc097a46b5d032.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
fixes: | ||
- | | ||
fix(grpc): This change fixes a bug in the grpc.aio support specific to streaming responses. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# isort: off | ||
from typing import ClassVar as _ClassVar | ||
from typing import Optional as _Optional | ||
|
||
from ddtrace.internal.compat import PYTHON_VERSION_INFO | ||
|
||
if PYTHON_VERSION_INFO > (3, 7): | ||
from google.protobuf import descriptor as _descriptor | ||
from google.protobuf import message as _message | ||
|
||
DESCRIPTOR: _descriptor.FileDescriptor | ||
class HelloReply(_message.Message): | ||
__slots__ = ["message"] | ||
MESSAGE_FIELD_NUMBER: _ClassVar[int] | ||
message: str | ||
def __init__(self, message: _Optional[str] = ...) -> None: ... | ||
class HelloRequest(_message.Message): | ||
__slots__ = ["name", "num_greetings"] | ||
NAME_FIELD_NUMBER: _ClassVar[int] | ||
NUM_GREETINGS_FIELD_NUMBER: _ClassVar[int] | ||
name: str | ||
num_greetings: str | ||
def __init__(self, name: _Optional[str] = ..., num_greetings: _Optional[str] = ...) -> None: ... |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! | ||
"""Client and server classes corresponding to protobuf-defined services.""" | ||
import grpc | ||
|
||
from ddtrace.internal.compat import PYTHON_VERSION_INFO | ||
|
||
|
||
if PYTHON_VERSION_INFO > (3, 7): | ||
from tests.contrib.grpc_aio import hellostreamingworld_pb2 as hellostreamingworld__pb2 | ||
|
||
class MultiGreeterStub(object): | ||
"""The greeting service definition.""" | ||
|
||
def __init__(self, channel): | ||
"""Constructor. | ||
Args: | ||
channel: A grpc.Channel. | ||
""" | ||
self.sayHello = channel.unary_stream( | ||
"/hellostreamingworld.MultiGreeter/sayHello", | ||
request_serializer=hellostreamingworld__pb2.HelloRequest.SerializeToString, | ||
response_deserializer=hellostreamingworld__pb2.HelloReply.FromString, | ||
) | ||
|
||
class MultiGreeterServicer(object): | ||
"""The greeting service definition.""" | ||
|
||
def sayHello(self, request, context): | ||
"""Sends multiple greetings""" | ||
context.set_code(grpc.StatusCode.UNIMPLEMENTED) | ||
context.set_details("Method not implemented!") | ||
raise NotImplementedError("Method not implemented!") | ||
|
||
def add_MultiGreeterServicer_to_server(servicer, server): | ||
rpc_method_handlers = { | ||
"sayHello": grpc.unary_stream_rpc_method_handler( | ||
servicer.sayHello, | ||
request_deserializer=hellostreamingworld__pb2.HelloRequest.FromString, | ||
response_serializer=hellostreamingworld__pb2.HelloReply.SerializeToString, | ||
), | ||
} | ||
generic_handler = grpc.method_handlers_generic_handler("hellostreamingworld.MultiGreeter", rpc_method_handlers) | ||
server.add_generic_rpc_handlers((generic_handler,)) | ||
|
||
# This class is part of an EXPERIMENTAL API. | ||
class MultiGreeter(object): | ||
"""The greeting service definition.""" | ||
|
||
@staticmethod | ||
def sayHello( | ||
request, | ||
target, | ||
options=(), | ||
channel_credentials=None, | ||
call_credentials=None, | ||
insecure=False, | ||
compression=None, | ||
wait_for_ready=None, | ||
timeout=None, | ||
metadata=None, | ||
): | ||
return grpc.experimental.unary_stream( | ||
request, | ||
target, | ||
"/hellostreamingworld.MultiGreeter/sayHello", | ||
hellostreamingworld__pb2.HelloRequest.SerializeToString, | ||
hellostreamingworld__pb2.HelloReply.FromString, | ||
options, | ||
channel_credentials, | ||
insecure, | ||
call_credentials, | ||
compression, | ||
wait_for_ready, | ||
timeout, | ||
metadata, | ||
) |
Oops, something went wrong.