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

[nodriver] Browser.stop throws exception if browser connection has failed #1949

Open
sohaib17 opened this issue Jul 15, 2024 · 0 comments
Open

Comments

@sohaib17
Copy link

Browser.start() adds newly launched process in registered instances and then tries to connect to the browser. But in case of slow hardware or high system load, Chrome takes some time to response and nodriver throws Failed to connect to browser and exits.

atexit handler util.deconstruct_browser() calls browser.stop() while exiting but since browser.connection haven't initialized yet, it fails with AttributeError. Leaving the running but unresponsive chrome in orphan state.

Exception:

Exception ignored in atexit callback: <function deconstruct_browser at 0x786c14bc85e0>
Traceback (most recent call last):
  File "/home/pyenv/lib/python3.12/site-packages/nodriver/core/util.py", line 138, in deconstruct_browser
    _.stop()
  File "/home/pyenv/lib/python3.12/site-packages/nodriver/core/browser.py", line 553, in stop
    asyncio.get_event_loop().create_task(self.connection.aclose())
                                         ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'aclose'

Fix:
In nodriver.core.browser.Browser.stop, add if self.connection: before close connection call.

# asyncio.get_running_loop().create_task(self.connection.send(cdp.browser.close()))
if self.connection:
    asyncio.get_event_loop().create_task(self.connection.aclose())
    logger.debug(
        "closed the connection using get_event_loop().create_task()"
    )

PS:
util.deconstruct_browser() still contains a print statement at the end. It should be changed to logger.info.

print("successfully removed temp profile %s" % _.config.user_data_dir)
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

No branches or pull requests

1 participant