Skip to content

fix: cleanup pending route handlers on close#1412

Merged
rwoll merged 10 commits into
microsoft:mainfrom
rwoll:fix/route-handler-leak
Jul 7, 2022
Merged

fix: cleanup pending route handlers on close#1412
rwoll merged 10 commits into
microsoft:mainfrom
rwoll:fix/route-handler-leak

Conversation

@rwoll
Copy link
Copy Markdown
Member

@rwoll rwoll commented Jul 7, 2022

Fixes #1402.

@rwoll rwoll requested a review from mxschmitt July 7, 2022 06:25
@rwoll
Copy link
Copy Markdown
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
Copy Markdown
Member Author

rwoll commented Jul 7, 2022

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

Comment thread playwright/_impl/_network.py
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
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread playwright/_impl/_helper.py Outdated
Comment thread playwright/_impl/_network.py
Comment thread tests/async/test_browsercontext_request_intercept.py
@rwoll rwoll requested a review from mxschmitt July 7, 2022 16:01
Comment thread playwright/_impl/_helper.py Outdated
@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