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

CallContext bug leads to context values bleeding #1462

Open
dualc opened this issue Oct 18, 2024 · 1 comment
Open

CallContext bug leads to context values bleeding #1462

dualc opened this issue Oct 18, 2024 · 1 comment
Labels

Comments

@dualc
Copy link

dualc commented Oct 18, 2024

I found some bugs about CallContext when I changed this jupyter to suppor multi-user/tenancy ,

@classmethod
def _get_map(cls) -> Dict[str, Any]:
"""Get the map of names to their values from the _NAME_VALUE_MAP context var.

    If the map does not exist in the current context, an empty map is created and returned.
    """
    ctx: Context = copy_context()
    if CallContext._name_value_map not in ctx:
        CallContext._name_value_map.set({})
    return CallContext._name_value_map.get()

copy_context is a shallow copy,_name_value_map is a dict,so when multi user visite jupyter,if we record some user infomation in context , it will casue context values bleeding

@dualc
Copy link
Author

dualc commented Oct 18, 2024

I found a solution to fix it. define a reset method in CallContext

    @classmethod
    def reset(cls):
        CallContext._name_value_map.set({})

when handler prepare,call the reset to set a dict to context

    async def prepare(self, *, _redirect_to_login=True) -> Awaitable[None] | None:  # type:ignore[override]
        """Prepare a response."""
        # Set the current Jupyter Handler context variable.
        CallContext.reset()
        CallContext.set(CallContext.JUPYTER_HANDLER, self)

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

No branches or pull requests

1 participant