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 shutdown error stack trace #989

Merged
merged 3 commits into from
Oct 28, 2024

Conversation

martin-purplefish
Copy link
Contributor

We would see stack traces when rooms exited:

--- Logging error ---
Traceback (most recent call last):
  File "/Users/martin/Library/Caches/pypoetry/virtualenvs/agent-x_OPPxuI-py3.12/lib/python3.12/site-packages/livekit/agents/ipc/job_main.py", line 52, in emit
    record = copy.copy(record)
             ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/copy.py", line 87, in copy
    rv = reductor(4)
         ^^^^^^^^^^^
ImportError: sys.meta_path is None, Python is likely shutting down
Call stack:
  File "/Users/martin/Library/Caches/pypoetry/virtualenvs/agent-x_OPPxuI-py3.12/lib/python3.12/site-packages/aiohttp/client.py", line 425, in __del__
    self._loop.call_exception_handler(context)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 1846, in call_exception_handler
    self.default_exception_handler(context)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 1820, in default_exception_handler
    logger.error('\n'.join(log_lines), exc_info=exc_info)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py", line 1568, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py", line 1684, in _log
    self.handle(record)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py", line 1700, in handle
    self.callHandlers(record)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
    hdlr.handle(record)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py", line 1028, in handle
    self.emit(record)
  File "/Users/martin/Library/Caches/pypoetry/virtualenvs/agent-x_OPPxuI-py3.12/lib/python3.12/site-packages/livekit/agents/ipc/job_main.py", line 68, in emit
    self.handleError(record)
Message: 'Unclosed client session\nclient_session: <aiohttp.client.ClientSession object at 0x127fa2de0>'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
  File "/Users/martin/Library/Caches/pypoetry/virtualenvs/agent-x_OPPxuI-py3.12/lib/python3.12/site-packages/livekit/agents/ipc/job_main.py", line 52, in emit
    record = copy.copy(record)
             ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/copy.py", line 87, in copy
    rv = reductor(4)
         ^^^^^^^^^^^
ImportError: sys.meta_path is None, Python is likely shutting down
Call stack:
  File "/Users/martin/Library/Caches/pypoetry/virtualenvs/agent-x_OPPxuI-py3.12/lib/python3.12/site-packages/aiohttp/connector.py", line 307, in __del__
    self._loop.call_exception_handler(context)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 1846, in call_exception_handler
    self.default_exception_handler(context)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 1820, in default_exception_handler
    logger.error('\n'.join(log_lines), exc_info=exc_info)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py", line 1568, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py", line 1684, in _log
    self.handle(record)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py", line 1700, in handle
    self.callHandlers(record)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
    hdlr.handle(record)
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/logging/__init__.py", line 1028, in handle
    self.emit(record)
  File "/Users/martin/Library/Caches/pypoetry/virtualenvs/agent-x_OPPxuI-py3.12/lib/python3.12/site-packages/livekit/agents/ipc/job_main.py", line 68, in emit
    self.handleError(record)
Message: "Unclosed connector\nconnections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x140c254f0>, 729943.46028), (<aiohttp.client_proto.ResponseHandler object at 0x140c24230>, 729943.706343791)]']\nconnector: <aiohttp.connector.TCPConnector object at 0x1406f64e0>"
Arguments: ()

Copy link

changeset-bot bot commented Oct 27, 2024

🦋 Changeset detected

Latest commit: 69d788b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
livekit-agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@martin-purplefish
Copy link
Contributor Author

PTAL @theomonnom @davidzhao

@martin-purplefish martin-purplefish changed the title Fix shutdown error Fix shutdown error stack trace Oct 27, 2024
Comment on lines 50 to 53
# Check if Python is shutting down
if not hasattr(sys, "meta_path") or sys.meta_path is None:
return

Copy link
Member

Choose a reason for hiding this comment

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

Would sys.is_finalizing() do the work instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed! Fixed!

Copy link
Member

@theomonnom theomonnom left a comment

Choose a reason for hiding this comment

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

Thanks!!

@theomonnom theomonnom changed the title Fix shutdown error stack trace fix shutdown error stack trace Oct 28, 2024
@theomonnom theomonnom merged commit 89ee168 into livekit:main Oct 28, 2024
2 of 4 checks passed
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.

2 participants