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

ContextVar LookupError on some requests #675

Closed
tim-schilling opened this issue Aug 18, 2021 · 0 comments · Fixed by #676
Closed

ContextVar LookupError on some requests #675

tim-schilling opened this issue Aug 18, 2021 · 0 comments · Fixed by #676

Comments

@tim-schilling
Copy link
Collaborator

There's a case where the usage of self._ctx.get() is throwing a LookupError.

I'm unable to reliably reproduce the issue.

LookupError: <ContextVar name='__scout_trackedrequest' at 0x7f241cd17ae0>
  File "django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "scout_apm/django/middleware.py", line 85, in __call__
    return self.get_response(request)
  File "contextlib.py", line 124, in __exit__
    next(self.gen)
  File "scout_apm/core/tracked_request.py", line 132, in span
    self.stop_span()
  File "scout_apm/core/tracked_request.py", line 124, in stop_span
    self.finish()
  File "scout_apm/core/tracked_request.py", line 169, in finish
    context.clear_tracked_request(self)
  File "scout_apm/core/context.py", line 136, in clear_tracked_request
    if self._ctx and self._token is not None and self._ctx.get() is instance:
@tim-schilling tim-schilling self-assigned this Aug 18, 2021
tim-schilling added a commit that referenced this issue Aug 19, 2021
* Define TrackedRequest ContextVar at module level.

Fixes #675

* Prevent a TrackedRequest from being sent more than once.

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

Successfully merging a pull request may close this issue.

1 participant