spotcast icon indicating copy to clipboard operation
spotcast copied to clipboard

Error in pychromecast socket - filedescriptor out of range in select()

Open alexandernajafi opened this issue 3 years ago • 3 comments

Bug Ticket

Describe the bug

Error log Error in select call: filedescriptor out of range in select() from spotcast.

I have a script casting Spotify to a Google Home Mini and have defined the device using the entity_id. It used to work but then one day it simply stopped working.

Service in script:

  - service: spotcast.start
    data:
      entity_id: media_player.sovrum_speaker
      uri: spotify:track:1VJRxqJhpEIpnHon7ssp1p
      repeat: track

Full error is

Logger: pychromecast.socket_client
Source: /usr/local/lib/python3.10/site-packages/pychromecast/socket_client.py:571
First occurred: 7 november 2022 04:35:53 (2669191 occurrences)
Last logged: 19:59:24

[device-name(ip):8009] Error in select call: filedescriptor out of range in select()
[device-name(ip):8009] Error in select call: filedescriptor out of range in select()
[device-name(ip):8009] Error in select call: filedescriptor out of range in select()
[device-name(ip):8009] Error in select call: filedescriptor out of range in select()
[device-name(ip):8009] Error in select call: filedescriptor out of range in select()

The error is followed by another error in the logs:

Logger: pychromecast.socket_client
Source: /usr/local/lib/python3.10/site-packages/pychromecast/socket_client.py:663
First occurred: 6 november 2022 18:24:39 (2672794 occurrences)
Last logged: 20:05:02

[device-name(ip):8009] Error communicating with socket, resetting connection
[device-name(ip):8009] Error communicating with socket, resetting connection
[device-name(ip):8009] Error communicating with socket, resetting connection
[device-name(ip):8009] Error communicating with socket, resetting connection
[device-name(ip):8009] Error communicating with socket, resetting connection
  • [x] Using latest version of spotcast
  • [x] Using latest stable version of Home Assistant
  • [x] I have setup the Spotify integration in Home Assistant
  • [x] I have Spotify Premium
  • [ ] I am using multiple accounts
  • [x] I have renewed my sp_dc and sp_key values and restarted Home Assistant (see README)
  • [x] I'm attaching relevant logs with level debug for component spotcast (see README)
  • [ ] I'm using entity_id in the service call and have tried device_name but the issue remains

Environment

  • Installation type: [HA_OS]
  • HA version: [2022.11.1]
  • spotcast version: [3.6.30]

Configuration

spotcast:
  sp_dc: -
  sp_key: -
  country: SE

Service Call

  - service: spotcast.start
    data:
      entity_id: media_player.sovrum_speaker
      uri: spotify:track:1VJRxqJhpEIpnHon7ssp1p
      repeat: track

Additional context

alexandernajafi avatar Nov 10 '22 19:11 alexandernajafi

A socket problem would be an indication of a netowrking issue on your homeassistant server, not spotcast. We sent a request to pychromecast, but it failed to return something when we asked.

fcusson avatar Nov 28 '22 13:11 fcusson

A socket problem would be an indication of a netowrking issue on your homeassistant server, not spotcast. We sent a request to pychromecast, but it failed to return something when we asked.

I understand why one would think so. But it did indeed work and as I see the log

Error in select call: filedescriptor out of range in select()

I would not assume it is a networking issue on the homeassistant server. It seems more like a library bug to me. Why would you get an out-of-range error otherwise?

alexandernajafi avatar Nov 28 '22 13:11 alexandernajafi

Hi @alexandernajafi, Coming back to older ticket now that we released v3.7.0.

I would not assume it is a networking issue on the homeassistant server. It seems more like a library bug to me. Why would you get an out-of-range error otherwise?

filedescriptor out of range coming from pychromecast means you were declined a new socket. Since in linux everything is a file, everything needs a file descriptor when you want to open it. When you open a socket, your linux kernel creates a file descriptor with a "file" where you write your content to send through the socket and where received data will be written to.

Linux machines have a limit to the number of file descriptor they can have at the same time (my main homelab per exemple is software limited to 1024, but has a hardware limit of 262,144). I would dig into that first. You can check with the following command:

ulimit -n
ulimit -n -H

This will tell you your soft and hard limit on file descriptors. The error you had was becasue, when you started the spotcast service you were already at the limit. You might have had other processes getting the error on your server, but simply managed it, or waited in line to get a PID. If you feel you are under utilizing your server capabilities, you can increase the soft limit has long as you are under the hard limit. You would have to do that by yourself, this is beyond providing support for spotcast itself.

fcusson avatar Mar 07 '23 13:03 fcusson