Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Handle local files without segfaulting #10

Closed
adamcik opened this issue Apr 24, 2011 · 5 comments
Closed

Handle local files without segfaulting #10

adamcik opened this issue Apr 24, 2011 · 5 comments
Labels
Milestone

Comments

@adamcik
Copy link
Contributor

adamcik commented Apr 24, 2011

One of my Spotify playlists was "infected" by a local file. This resulted in following problem in handling of artist in pyspotify. Exact details of problem are a bit fuzzy, but problem seems to be with the artist object when calling name. There is also a related mopidy issue here which I will take care of.

http://open.spotify.com/user/adamcik/playlist/0ii9t5LUsjgTL7XY0s6mqM can be used to reproduce.

ERROR    2011-04-25 00:38:11,361 [4297:SpotifySMThread] mopidy.utils.process
  'utf8' codec can't decode bytes in position 1-4: invalid data
Traceback (most recent call last):
  File "/home/adamcik/dev/mopidy/mopidy/utils/process.py", line 21, in run
    self.run_inside_try()
  File "/home/adamcik/dev/mopidy/mopidy/backends/spotify/session_manager.py", line 40, in run_inside_try
    self.connect()
  File "/usr/local/lib/python2.6/dist-packages/pyspotify-1.1-py2.6-linux-i686.egg/spotify/manager.py", line 44, in connect
    self.loop(sess) # returns on disconnect
  File "/usr/local/lib/python2.6/dist-packages/pyspotify-1.1-py2.6-linux-i686.egg/spotify/manager.py", line 54, in loop
    self.timer = threading.Timer(timeout/1000.0, self.awoken.set)
  File "/usr/lib/python2.6/threading.py", line 711, in Timer
    return _Timer(*args, **kwargs)
  File "/usr/lib/python2.6/threading.py", line 722, in __init__
    Thread.__init__(self)
  File "/usr/lib/python2.6/threading.py", line 436, in __init__
    self.__daemonic = self._set_daemon()
  File "/usr/lib/python2.6/threading.py", line 448, in _set_daemon
    return current_thread().daemon
  File "/usr/lib/python2.6/threading.py", line 810, in currentThread
    return _active[_get_ident()]
  File "/home/adamcik/dev/mopidy/mopidy/backends/spotify/session_manager.py", line 73, in metadata_updated
    self.refresh_stored_playlists()
  File "/home/adamcik/dev/mopidy/mopidy/backends/spotify/session_manager.py", line 127, in refresh_stored_playlists
    SpotifyTranslator.to_mopidy_playlist(spotify_playlist))
  File "/home/adamcik/dev/mopidy/mopidy/backends/spotify/translator.py", line 60, in to_mopidy_playlist
    tracks=[cls.to_mopidy_track(t) for t in spotify_playlist],
  File "/home/adamcik/dev/mopidy/mopidy/backends/spotify/translator.py", line 41, in to_mopidy_track
    artists=[cls.to_mopidy_artist(a) for a in spotify_track.artists()],
  File "/home/adamcik/dev/mopidy/mopidy/backends/spotify/translator.py", line 19, in to_mopidy_artist
    name=spotify_artist.name().decode(ENCODING),
  File "/home/adamcik/dev/mopidy/lib/python2.6/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 1-4: invalid data
zsh: segmentation fault  GST_DEBUG=2 python mopidy --verbose
@adamcik
Copy link
Contributor Author

adamcik commented Jun 2, 2011

To elaborate a bit more, actual problem is that we are trying to access the name for an artist that Spotify does not know about. This might be similar to the other missing null check cases we have had.

@jodal
Copy link
Owner

jodal commented Jun 8, 2011

We believe this is fixed by pull request #19.

@jodal jodal closed this as completed Jun 8, 2011
@liamw9534
Copy link

I just encountered a similar problem to this whereby some file(s) became corrupted in my local .config/mopidy/spotifty area. I could only solve this by deleting the whole cache and restarting - not sure if there is a better way of protecting against corrupted cache files? Some suggestions:

  • We could try to detect certain types of exception when accessing outside world data, esp. stuff from spotify which is potentially cached.
  • We could raise an event to the mopidy-spotify session manager which tries to take appropriate action; presumably deleting the cache and re-loading the session is harmless enough?

Sorry, forgot to add...here is the code section which blew up:

    def log_message(self, session, data):
        """Callback used by pyspotify"""
        logger.debug('System message: %s' % data.strip())
        if 'offline-mgr' in data and 'files unlocked' in data:
            # XXX This is a very very fragile and ugly hack, but we get no
            # proper event when libspotify is done with initial data loading.
            # We delay the expensive refresh of Mopidy's playlists until this
            # message arrives. This way, we avoid doing the refresh once for
            # every playlist or other change. This reduces the time from
            # startup until the Spotify backend is ready from 35s to 12s in one
            # test with clean Spotify cache. In cases with an outdated cache
            # the time improvements should be a lot greater.
            if not self._initial_data_receive_completed:
                self._initial_data_receive_completed = True
                self.refresh_playlists()

@jodal
Copy link
Owner

jodal commented Sep 25, 2014

The original issue here was not handling "local tracks" right (ref. http://pyspotify.mopidy.com/en/latest/api/session/#spotify.Session.get_local_track), and nothing to do with the cache or other files stored by libspotify on local disk.

Also, pyspotify 1.x and Mopidy-Spotify 1.x is a dead end, about to be replaced by the 2.x reimplementation of both projects.

@liamw9534
Copy link

@jodal Understood! I actually posted to this issue since it helped me troubleshoot the problem I was having...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants