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

Fix UnboundLocalError in asgi handler #1564

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mike-baker-on
Copy link

Description

Currently the duration calculation in the ASGI instrumentation fails if anything outside the self.app call raises an error because start will not have been instantiated.

This hides any instansation errors are actually occurring since they will be replaced by the UnboundLocalError

This PR moves the duration tracking into its own try/finally block so it will not be ran unless self.app was called.

It would have also been possible to set start to None at the top of the function and then have an if statement inside the finally block, however I decided that was too close to overloading the concept of the start variable as a should record duration control flow flag.

The actual issue is a unicode decoding error in the handling of headers, however since #1492 potentially fixes this issue too I have restricted the scope of this PR to be focused on error propagation.

Fixes (#1478)

Type of change

  • [ x] Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added new unit test (test_failed_instrumentation_errors_propagate) it currently uses the server_request_hook functionality to force an instrumentation error without relying on any specific bugs.

The test does also rely on setting self.communicator to None in order to prevent the error being re-raised in teardown, relevant code links:

https:/open-telemetry/opentelemetry-python/blob/b184dc95844561f0dce3f5c0a496bc89d0fb9a6d/tests/opentelemetry-test-utils/src/opentelemetry/test/asgitestutil.py#L38

https:/django/asgiref/blob/36022636d3390c1c1cbb952336a34d652a6bfb26/asgiref/testing.py#L8

Does This PR Require a Core Repo Change?

  • Yes.
  • [ x] No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • [ x] Unit tests have been added
  • Documentation has been updated

@linux-foundation-easycla
Copy link

CLA Not Signed

@thomasleveil
Copy link
Contributor

I guess this may be closed since #1889 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Instrumentation raises uncaught exception on non utf-8 request header sequences
2 participants