holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.8k stars 519 forks source link

Refresh token task warning: A separate task was already scheduled under the name #7494

Open ajstewart opened 1 week ago

ajstewart commented 1 week ago

ALL software version info

(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc should be added within the dropdown below.)

Software Version Info ```plaintext bokeh 3.6.1 panel 1.5.3 macOS 15.0.1 ```

Description of expected behavior and the observed behavior

It's hard to come up with a reproducible example as it's related to auth, but recently I've started to see this following warning when a user refreshes their session or logs on again

WARNING:param._state00002: A separate task was already scheduled under the name '66652_Joe Bloggs-refresh-access-tokens'. The new task will be ignored. If you want to replace the existing task cancel it with `state.cancel_task('66652_Joe Bloggs-refresh-access-tokens')` before adding adding a new task under the same name.
2024-11-14 11:49:02,311 A separate task was already scheduled under the name '66652_Joe Bloggs-refresh-access-tokens'. The new task will be ignored. If you want to replace the existing task cancel it with `state.cancel_task('66652_Joe Bloggs-refresh-access-tokens')` before adding adding a new task under the same name.

I am using a generic auth type with an Azure B2C setup.

I'm reporting this because as far I can see the task is actually attempted to be canceled before creating the new one:

https://github.com/holoviz/panel/blob/e24f44342908b33bf38ab0c4c3e784d50063034a/panel/auth.py#L1133-L1140

I'm not sure where the number comes from in the task name, it seems to be attached to the user.

I don't think this is harming anything to do with the app, but it seems unexpected given the code above.

I am running the app via the CLI: panel serve src/app.py --autoreload --static-dirs assets=./src/assets --port 5006 --setup src/app_setup.py

Complete, minimal, self-contained example code that reproduces the issue

Stack traceback and/or browser JavaScript console output

Screenshots or screencasts of the bug in action

sblowers commented 4 days ago

There looks to be a disconnect between the naming for schedule_task and cancel_task in panel/io/state.py

In schedule_task the task name is prepended with the PID https://github.com/holoviz/panel/blob/8421976315af703933e634b7180476a459a16ca1/panel/io/state.py#L857-L870

However in cancel_task it assumes that the name given exactly matches the task to remove. So without the PID, it assumes the task doesn't exist and probably raises a KeyError https://github.com/holoviz/panel/blob/8421976315af703933e634b7180476a459a16ca1/panel/io/state.py#L575-L591

To fix, you would probably need to add the PID to the call in the auth.py to match how the task is created, or update the cancel_task function to always add the PID to the task name being cancelled

hoxbro commented 4 days ago

@sblowers, thank you for the investigation!

This is an oversight. Can you submit a PR with your suggested change in cancel_task?