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

Occasional crash #11

Closed
yochananmarqos opened this issue Jun 18, 2021 · 5 comments
Closed

Occasional crash #11

yochananmarqos opened this issue Jun 18, 2021 · 5 comments

Comments

@yochananmarqos
Copy link

I use the following script on system startup:

#!/bin/bash

export SECONDS=60
cast_control service connect --name "Marks_TV" --icon --wait $SECONDS &

Occasionally I notice cast_control is no longer running and find this in the log:

~/.cache/cast_control/log/cast_control.log:

ERROR:daemons.startstop.simple:Uncaught exception in the daemon run() method.
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/daemons/startstop/simple.py", line 48, in start
    self.run()
  File "/usr/lib/python3.9/site-packages/cast_control/daemon.py", line 71, in run
    self.target()
  File "/usr/lib/python3.9/site-packages/cast_control/run.py", line 93, in run_safe
    run_server(*args)
  File "/usr/lib/python3.9/site-packages/cast_control/run.py", line 77, in run_server
    mpris = retry_until_found(name, host, uuid, wait, retry_wait)
  File "/usr/lib/python3.9/site-packages/cast_control/run.py", line 54, in retry_until_found
    mpris = create_adapters_and_server(name, host, uuid, retry_wait)
  File "/usr/lib/python3.9/site-packages/cast_control/run.py", line 26, in create_adapters_and_server
    device = find_device(name, host, uuid, retry_wait)
  File "/usr/lib/python3.9/site-packages/cast_control/base.py", line 208, in find_device
    device = get_device(name, retry_wait)
  File "/usr/lib/python3.9/site-packages/cast_control/base.py", line 171, in get_device
    devices, service_browser = get_chromecasts(retry_wait=retry_wait)
  File "/usr/lib/python3.9/site-packages/pychromecast/__init__.py", line 225, in get_chromecasts
    get_chromecast_from_cast_info(
  File "/usr/lib/python3.9/site-packages/pychromecast/__init__.py", line 86, in get_chromecast_from_cast_info
    return Chromecast(
  File "/usr/lib/python3.9/site-packages/pychromecast/__init__.py", line 337, in __init__
    self.socket_client = socket_client.SocketClient(
  File "/usr/lib/python3.9/site-packages/pychromecast/socket_client.py", line 201, in __init__
    self.socketpair = socket.socketpair()
  File "/usr/lib/python3.9/socket.py", line 606, in socketpair
    a, b = _socket.socketpair(family, type, proto)
OSError: [Errno 24] Too many open files
@alexdelorenzo
Copy link
Owner

alexdelorenzo commented Jun 22, 2021

Thanks opening an issue and including logs with it. Also, thanks for packaging this project on the AUR!

Can you post the output of the following commands?

#!/usr/bin/env bash

echo $(python3 --version)
echo $(cast_control --version)
python3 -m pip show cast_control mpris_server PyChromecast

In your launch script, if you add --log-level debug, it will log more information that can make this easier to debug, as well.

It looks like the daemon is hitting your system's limit for per-process open file descriptors. I'm guessing that pychromecast.get_chromecasts() results in opening socket fds that aren't closed and the loop in cast_control.run.retry_until_found() causes it to open new socket fds until the limit is hit. I'll try to test and see if this is the issue.

Do you turn off your Chromecast or sometimes use your computer on networks that you can't access your Chromecast from?

As an aside, if you use the service connect command, you shouldn't need to use the & Bash feature to run cast_control in the background, as it will daemonize itself.

@yochananmarqos
Copy link
Author

Python 3.9.5
cast_control v0.10.11
Name: cast-control
Version: 0.10.11
Summary: 📺 Control Chromecasts from Linux and D-Bus
Home-page: https://github.com/alexdelorenzo/cast_control
Author: Alex DeLorenzo <alex@alexdelorenzo.dev>
Author-email: None
License: AGPL-3.0
Location: /usr/lib/python3.9/site-packages
Requires: appdirs, click, daemons, PyChromecast, pydbus, PyGObject, aiopath, mpris-server, typing-extensions
Required-by: 
---
Name: mpris-server
Version: 0.2.18
Summary: Publish a MediaPlayer2 MPRIS device to D-Bus.
Home-page: https://alexdelorenzo.dev
Author: Alex DeLorenzo
Author-email: None
License: AGPL-3.0
Location: /usr/lib/python3.9/site-packages
Requires: PyGObject, pydbus, unidecode, emoji
Required-by: cast-control
---
Name: PyChromecast
Version: 9.2.0
Summary: Python module to talk to Google Chromecast.
Home-page: https://github.com/balloob/pychromecast
Author: Paulus Schoutsen
Author-email: paulus@paulusschoutsen.nl
License: MIT
Location: /usr/lib/python3.9/site-packages
Requires: protobuf, zeroconf, casttube
Required-by: cast-control

My Chromecast is always plugged in, but the TV is off most of the day. My laptop is always on and on the same Wi-Fi network.

@alexdelorenzo
Copy link
Owner

alexdelorenzo commented Jun 24, 2021

Thanks @yochananmarqos. I pushed some changes to PyPI that address a cause for the app hitting the open socket descriptor limit.

You can try the changes out by upgrading cast_control and mpris_server:

$ python3 -m pip install cast_control==0.11.3
$ python3 -m pip install mpris_server==0.3.4

I haven't reproduced the bug myself because I need to run cast_control longer in order to hit the open fd limit, but I'm pretty confident that the issue was addressed with 033536e, at least partially if not fully.

@yochananmarqos
Copy link
Author

I'll let you know if it happens again.

@alexdelorenzo
Copy link
Owner

I'm going to close this issue. Feel free to open a new issue if you run into this issue again.

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

2 participants