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

Prevent RuntimeError for Flask on context.detach with the same token #3099

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

Conversation

abo-abo
Copy link

@abo-abo abo-abo commented Dec 12, 2024

Description

This happens for me when using werkzeug's debug=True. In this case, the token was already detached. But when I enter an expression into the debug console, we attempt to detach the token once more.

This causes a RuntimeError, as expected: https://peps.python.org/pep-0567/#contextvars-contextvar.

But if we set _ENVIRON_TOKEN to None after we detach, this won't happen.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Create a simple Flask app with instrumented spans
  • Raise an error in one of the routes and open the debugger web page
  • Click the shell icon and enter the debugger PIN
  • Try to examine any variables in the context
    • doing so will produce a RuntimeError in the logs, since the token was already used to detach the context on the original request

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

This happens for me when using werkzeug's debug=True.
In this case, the token was already detached. But when I enter an
expression into the debug console, we attempt to detach the token once
more.

This causes a RuntimeError, as expected: https://peps.python.org/pep-0567/#contextvars-contextvar.

But if we set _ENVIRON_TOKEN to None after we detach, this won't happen.
Copy link

linux-foundation-easycla bot commented Dec 12, 2024

CLA Signed


The committers listed above are authorized under a signed CLA.

@xrmx
Copy link
Contributor

xrmx commented Dec 13, 2024

We need the CLA signed in order to get things accepted.

@abo-abo
Copy link
Author

abo-abo commented Dec 13, 2024

Just signed the CLA.

@abo-abo
Copy link
Author

abo-abo commented Dec 19, 2024

Friendly ping, can we merge this?

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.

2 participants