[GH-ISSUE #61] [Bug Report] Librespot Buffer.read() Bad File Descriptor Exception #49

Closed
opened 2026-02-27 04:57:16 +03:00 by kerem · 1 comment
Owner

Originally created by @ulyxie on GitHub (Aug 22, 2025).
Original GitHub issue: https://github.com/Googolplexed0/zotify/issues/61

Originally assigned to: @Googolplexed0 on GitHub.

Bug Description
Crash appeared after 27 hours during the self.__socket.send(self.__buffer.read()) operation in core.py of librespot. In one of my responses in issue #56 I mentioned this exception and that it happened after 2 hours.

Bug Triggering Command

zotify \
  --download-lyrics=true \
  --download-format=mp3 \
  --download-quality=very_high \
  --debug \
  -rp . \
  -ie True \
  --md-allgenres True \
  --retry-attempts 5 \
  --bulk-wait-time=10 \
  -rt True \
  -f songs.txt

songs.txt contains 13 private playlists, 4 of which have 600 to 800 songs.

Error Traceback / Logs

Traceback (most recent call last):
  File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/zotify/track.py", line 292, in download_track
    stream = Zotify.get_content_stream(track, Zotify.DOWNLOAD_QUALITY)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/zotify/config.py", line 619, in get_content_stream
    return cls.SESSION.content_feeder().load(content_id, VorbisOnlyAudioQuality(quality), False, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 741, in load
    return self.load_track(playable_id, audio_quality_picker, preload,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 802, in load_track
    return self.load_stream(file, track, None, preload, halt_listener)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 756, in load_stream
    return CdnFeedHelper.load_track(self.__session, track, file,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 339, in load_track
    key = session.audio_key().get_audio_key(track.gid, file.file_id)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 271, in get_audio_key
    self.__session.send(Packet.Type.request_key, out.read())
  File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/core.py", line 1296, in send
    self.__send_unchecked(cmd, payload)
  File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/core.py", line 1388, in __send_unchecked
    self.cipher_pair.send_encoded(self.connection, cmd, payload)
  File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/crypto.py", line 45, in send_encoded
    connection.flush()
  File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/core.py", line 1920, in flush
    self.__socket.send(self.__buffer.read())
OSError: [Errno 9] Bad file descriptor

zotify_DEBUG_2025-08-21_09-45-09.log

Config File
config_DEBUG.json

Zotify Version
v0.9.25

Additional Context
The environment that zotify is being used in is:

  • debian 12
  • zotify via pipx
  • storage location for the songs: SMB/CIFS via tailscale connection. This is different than my previous exception of this type which was storing songs to local storage so I think storage location doesn't play any role.
Originally created by @ulyxie on GitHub (Aug 22, 2025). Original GitHub issue: https://github.com/Googolplexed0/zotify/issues/61 Originally assigned to: @Googolplexed0 on GitHub. **Bug Description** Crash appeared after 27 hours during the self.__socket.send(self.__buffer.read()) operation in core.py of librespot. In one of my responses in issue #56 I mentioned this exception and that it happened after 2 hours. **Bug Triggering Command** ``` zotify \ --download-lyrics=true \ --download-format=mp3 \ --download-quality=very_high \ --debug \ -rp . \ -ie True \ --md-allgenres True \ --retry-attempts 5 \ --bulk-wait-time=10 \ -rt True \ -f songs.txt ``` songs.txt contains 13 private playlists, 4 of which have 600 to 800 songs. **Error Traceback / Logs** ``` Traceback (most recent call last): File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/zotify/track.py", line 292, in download_track stream = Zotify.get_content_stream(track, Zotify.DOWNLOAD_QUALITY) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/zotify/config.py", line 619, in get_content_stream return cls.SESSION.content_feeder().load(content_id, VorbisOnlyAudioQuality(quality), False, None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 741, in load return self.load_track(playable_id, audio_quality_picker, preload, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 802, in load_track return self.load_stream(file, track, None, preload, halt_listener) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 756, in load_stream return CdnFeedHelper.load_track(self.__session, track, file, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 339, in load_track key = session.audio_key().get_audio_key(track.gid, file.file_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 271, in get_audio_key self.__session.send(Packet.Type.request_key, out.read()) File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/core.py", line 1296, in send self.__send_unchecked(cmd, payload) File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/core.py", line 1388, in __send_unchecked self.cipher_pair.send_encoded(self.connection, cmd, payload) File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/crypto.py", line 45, in send_encoded connection.flush() File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/core.py", line 1920, in flush self.__socket.send(self.__buffer.read()) OSError: [Errno 9] Bad file descriptor ``` [zotify_DEBUG_2025-08-21_09-45-09.log](https://github.com/user-attachments/files/21937183/zotify_DEBUG_2025-08-21_09-45-09.log) **Config File** [config_DEBUG.json](https://github.com/user-attachments/files/21937195/config_DEBUG.json) **Zotify Version** v0.9.25 **Additional Context** The environment that zotify is being used in is: - debian 12 - zotify via pipx - storage location for the songs: SMB/CIFS via tailscale connection. This is different than my previous exception of this type which was storing songs to local storage so I think storage location doesn't play any role.
kerem 2026-02-27 04:57:16 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@Googolplexed0 commented on GitHub (Aug 23, 2025):

File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/core.py", line 1920, in flush
self.__socket.send(self.__buffer.read())
OSError: [Errno 9] Bad file descriptor

Some digging is leading me to believe that it tried to run the .send() method when the .__socket was either not opened yet or had already been closed. No idea why this would happen at all, nor only after 27 hours of running. Maybe after a long period of not downloading any tracks your OS killed/closed the socket? Might also be some kind of rare race condition (similar to this bug) or a random error.

storage location for the songs: SMB/CIFS via tailscale connection. This is different than my previous exception of this type which was storing songs to local storage so I think storage location doesn't play any role.

Definitely a networking/connection thing rather than a storage thing. I think the "bad file descriptor" is a misnomer for the buffer the socket is writing to rather than a user-facing file. Unfortunately an error occurring within socket.send() is probably too low-level for me to track down or help fix.

<!-- gh-comment-id:3216242213 --> @Googolplexed0 commented on GitHub (Aug 23, 2025): > File "/home/helio/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/core.py", line 1920, in flush > self.__socket.send(self.__buffer.read()) > OSError: [Errno 9] Bad file descriptor Some digging is leading me to believe that it tried to run the `.send()` method when the `.__socket` was either not opened yet or had already been closed. No idea why this would happen at all, nor only after 27 hours of running. Maybe after a long period of not downloading any tracks your OS killed/closed the socket? Might also be some kind of rare race condition (similar to [this](https://bugs.python.org/issue43842) bug) or a random error. > storage location for the songs: SMB/CIFS via tailscale connection. This is different than my previous exception of this type which was storing songs to local storage so I think storage location doesn't play any role. Definitely a networking/connection thing rather than a storage thing. I think the "bad file descriptor" is a misnomer for the buffer the socket is writing to rather than a user-facing file. Unfortunately an error occurring within `socket.send()` is probably too low-level for me to track down or help fix.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/zotify#49
No description provided.