[SLES-2666] handle_end_invocation race condition #1024
Draft
+8
−8
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.
Overview
anonymousTaskhandle_end_invocationthen immediately returns 200 so the tracer can continueanonymousTaskis busy with a complex body inextract_request_bodyfor the time beingPlatformRuntimeDoneis processedinitialization_type: SnapStart) thenPlatformRuntimeDonetries to pair_platform_runtime_done_event which isNonebecauseanonymousTaskis still busy with the bodyanonymousTaskfinally completes, but that's irrelevant becausesend_ctx_spansis only run onPlatformRuntimeDonewhich assumes universal_instrumentation_end has already been sentWhy this looks likely
In the customer's logs we can see
05:11:48.463datadog.trace.agent.core.DDSpan - Finished span (WRITTEN): DDSpan [ t_id=274254290101965219205:11:48.489PlatformRuntimeDone received05:11:48.630REPORT RequestId1db22159-7200-43c8-bec1-11b89df4f099(last log emitted in an execution)05:11:53.784START RequestId:8c801767-e21b-43f7-bd11-078bb64bc430(new request id, 5s later)05:11:53.789Received end invocation request from headers:{""x-datadog-trace-id"": ""2742542901019652192"... -> we are now trying to finish the span after the request is long gone 🙃In this specific run, the lambda even had time to stop before continuin with the anonymous task from
handle_end_invocation.Performance
This PR makes the reading of the body synchronous with the response. This will delay handing over execution to outside the extension until the body is read. But that is irrelevant because it is a requirement to read the body and send
universal_instrumentation_endbefore relinquishing control.Testing
Suggestions very welcome