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: cleanup pending route handlers on close #1412

Merged
merged 10 commits into from Jul 7, 2022

Conversation

rwoll
Copy link
Member

@rwoll rwoll commented Jul 7, 2022

Fixes #1402.

@rwoll rwoll requested a review from mxschmitt July 7, 2022 06:25
@rwoll
Copy link
Member Author

rwoll commented Jul 7, 2022

The tests cover the case originally reported in #1402 (comment); however, we should also add a test for the disable interception race reported in #1402 (comment).

@rwoll rwoll marked this pull request as draft July 7, 2022 06:33
@rwoll
Copy link
Member Author

rwoll commented Jul 7, 2022

Converting to a draft—this worked locally but CI says different!

rwoll added a commit to rwoll/playwright-python that referenced this pull request Jul 7, 2022
@rwoll rwoll mentioned this pull request Jul 7, 2022
@rwoll rwoll marked this pull request as ready for review July 7, 2022 09:23
@rwoll rwoll requested a review from mxschmitt July 7, 2022 09:42
def __init__(self) -> None:
self._pending_tasks: List[asyncio.Task] = []

def create_task(self, coro: Coroutine) -> asyncio.Task:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of creating the task here, I'd pass the task over and create it externally.

Copy link
Member Author

@rwoll rwoll Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the advantage of creating it externally? We need to tightly control background tasks, so it seems safest to encapsulate all that's needed to do so like we have done here.

i.e. Don't use asyncio.create_task,—this will create leaks. Use BackgroundTaskTracker.create_task and we'll handle everything for you (like adding a done callback, adding it to pending tasks, and cancelling it eventually).

The thing that breaks us is calling asyncio.create_task and then not tracking it, so we replace the call that you need to use to create the task, and ensure it's being registered and cleaned up properly.

@rwoll rwoll requested a review from mxschmitt July 7, 2022 16:01
@rwoll rwoll requested a review from pavelfeldman July 7, 2022 18:26
@rwoll rwoll merged commit c8d8f4a into microsoft:main Jul 7, 2022
rwoll added a commit to rwoll/playwright-python that referenced this pull request Jul 7, 2022
rwoll added a commit to rwoll/playwright-python that referenced this pull request Jul 13, 2022
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.

[Question]: Task was destroyed but it is pending! in route.abort()
2 participants