Skip to content

[Bug]: "Future exception was never retrieved" on SIGINT (Ctrl+C) #41992

Description

@2mitrij

Version

1.61.0 (from PyPi)

Steps to reproduce

import asyncio
import random
import string
from collections.abc import Mapping
from contextlib import suppress
from types import MappingProxyType
from typing import Any
from urllib.parse import urljoin

from playwright.async_api import Error as PlaywrightError
from playwright.async_api import Page, async_playwright

PLAYWRIGHT_BROWSER_ARGS = ()
PLAYWRIGHT_LAUNCH_KWARGS: Mapping[str, Any] = MappingProxyType({
    'channel': 'chromium',
    'handle_sigint': False,
})
ROOT_URL = 'https://example.com/'


def make_random_url() -> str:
    path = ''.join(random.choices(string.ascii_letters + string.digits, k=20))
    return urljoin(ROOT_URL, path)


async def request_urls(page: Page) -> None:
    while True:
        url = make_random_url()
        print(f'Requesting url: "{url}"')
        try:
            response = await page.goto(url)
        except PlaywrightError as e:
            print(f'Page goto error: {e}')
        print(f'Response code: {response.status}')


async def main() -> None:
    try:
        async with (
            async_playwright() as playwright_instance,
            await playwright_instance.chromium.launch(args=PLAYWRIGHT_BROWSER_ARGS, **PLAYWRIGHT_LAUNCH_KWARGS) as browser,
            await browser.new_context() as context,
            await context.new_page() as page,
        ):
            await request_urls(page)
    except PlaywrightError as err:
        print(f'Playwright error: {err}')


if __name__ == '__main__':
    with suppress(KeyboardInterrupt):
        asyncio.run(main())
  1. Create python venv: python3.11 -m venv .venv
  2. Activate venv: source .venv/bin/activate
  3. Install playwright: pip install playwright
  4. Run script: python script.py
  5. Wait for "Requesting url ..." to appear
  6. Press Ctrl+C

Expected behavior

Successfull shutdown without errors and warnings.

Actual behavior

Requesting url: "https://example.com/1R4vlh1NDz2EfdWHN2pB"
Response code: 404
Requesting url: "https://example.com/eCe8LRJqnn8tzYscMvWQ"
Response code: 404
Requesting url: "https://example.com/ClJGpt7qjnJGdoGOOSOK"
Response code: 404
Requesting url: "https://example.com/GzLEq2bWEVHyBozJZwJ4"
Response code: 404
Requesting url: "https://example.com/LVz9cCD5szudUS0nlC7a"
^CFuture exception was never retrieved
future: <Future finished exception=Error('net::ERR_ABORTED; maybe frame was detached?\nCall log:\n  - navigating to "https://example.com/LVz9cCD5szudUS0nlC7a", waiting until "load"\n')>
playwright._impl._errors.Error: net::ERR_ABORTED; maybe frame was detached?
Call log:
  - navigating to "https://example.com/LVz9cCD5szudUS0nlC7a", waiting until "load"

Additional context

Run on WSL (Win 11)

Environment

System:
    OS: Linux 6.18 Ubuntu 24.04.4 LTS 24.04.4 LTS (Noble Numbat)
    CPU: (10) x64 13th Gen Intel(R) Core(TM) i5-13400
    Memory: 6.83 GB / 15.62 GB
    Container: Yes
  Binaries:
    Node: 18.19.1 - /usr/bin/node
    npm: 9.2.0 - /usr/bin/npm
  IDEs:
    VSCode: 1.130.0 - /mnt/c/Users/user/AppData/Local/Programs/Microsoft VS Code/bin/code
  Languages:
    Bash: 5.2.21 - /usr/bin/bash

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions