jodal / pyspotify

Python bindings for libspotify (no longer working as of May 2022)
https://pyspotify.readthedocs.io
Apache License 2.0
519 stars 93 forks source link

Segmentation fault after running for a while #53

Closed wolph closed 12 years ago

wolph commented 12 years ago

I have not yet been able to trace down the exact issue, but every time I play a couple of songs (~15 minutes) my app crashes with a segmentation fault.

Little information about my environment:

Here's a small part of the strace output:

access("tmp/Users/wolph-user/playlist-c3a5cea4027d5705c2ee69b02fc3c13002.bnk.tmp", F_OK) = -1 ENOENT (No such file or directory)                                                                                                                                                                                            
open("tmp/Users/wolph-user/playlist-c3a5cea4027d5705c2ee69b02fc3c13002.bnk.tmp", O_WRONLY|O_CREAT|O_TRUNC, 0664) = 28                                                                                                                                                                                                       
fcntl(28, F_SETFD, FD_CLOEXEC)          = 0                                                                                                                                                                                                                                                                                 
write(28, "SPCO\26\0\0\0\1\24PlaylistWithMetadata\334\37"..., 8192) = 8192                                                                                                                                                                                                                                                  
write(28, "\372\37[\250B\2024\225\0@\t\20\306\27\t\377}NC(\256g\366\251\360>5?\10\330\17x"..., 8192) = 8192                                                                                                                                                                                                                 
write(28, "\372\37Xx@0\17\10\17x\4\1\20[!\227{s\303O\377\277\244~\224\350\345\311\276\t\27E"..., 8192) = 8192                                                                                                                                                                                                               
write(28, "\372\37\22\330\223\2110\236\10\200\304\23x\10\0\10\1\200\2\17\10\17x\4\1\20#\324s\356\222'"..., 8192) = 8192                                                                                                                                                                                                     
write(28, "\372\37\245~\352\n\377\3\v\357\2244\35\10\277\366\355\367\4\10\207\200\372\367\4\10)\25\24\1\24\320"..., 8192) = 8192                                                                                                                                                                                            
write(28, "\372\37\24a\357\310 Esper, Rebecca Naomi Jone"..., 8192) = 8192                                                                                                                                                                                                                                                  
write(28, "\372\37\275\231\247?ne/She's A Rebel\t\20\363'\243\21\214\311D="..., 8192) = 8192                                                                                                                                                                                                                                
write(28, "\372\37\250\310\312\356I>\247+JjN\357vd\10\277\366\355\367\4\10\210\200\372\367\4\10\16\25\24"..., 8192) = 8192                                                                                                                                                                                                  
write(28, "\372\37v\361k\264\10\5\t\20\22\7\1S\323\271G\322\225i\375\252\16]\1\267\10\277\366\355\367\4"..., 8192) = 8192                                                                                                                                                                                                   
write(28, "\372\37\335\0\262\343\274<\222\3\32\217\220\23\t\nLonely Day\t\20\254\4\364\346"..., 8192) = 8192                                                                                                                                                                                                                
write(28, "\372\37\330\231Bo\327\207\10\200\342\tx\1\24\353\307\272\337\206\32\r\245\24\35}\262\377\203\34\351\226"..., 8192) = 8192                                                                                                                                                                                        
write(28, "Y\25\375F\307^\20\25\267\276g\361WFh\243\237\254\326\265\256\370\305\20\317\t\343\273\361OE\311"..., 5473) = 5473                                                                                                                                                                                                
close(28)                               = 0                                                                                                                                                                                                                                                                                 
rename("tmp/Users/wolph-user/playlist-c3a5cea4027d5705c2ee69b02fc3c13002.bnk.tmp", "tmp/Users/wolph-user/playlist-c3a5cea4027d5705c2ee69b02fc3c13002.bnk") = 0                                                                                                                                                              
write(27, "SPCO\17\0\0\0\1\rPlaylistCache\177\v`\3235\276\0\220\301"..., 2974) = 2974                                                                                                                                                                                                                                       
close(27)                               = 0                                                                                                                                                                                                                                                                                 
rename("tmp/Users/wolph-user/playlist.bnk.tmp", "tmp/Users/wolph-user/playlist.bnk") = 0                                                                                                                                                                                                                                    
unlink("tmp/Users/wolph-user/playlist") = -1 ENOENT (No such file or directory)                                                                                                                                                                                                                                             
clone(child_stack=0x7f4ade7fbfd0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f4ade7fc9d0, tls=0x7f4ade7fc700, child_tidptr=0x7f4ade7fc9d0) = 12079                                                                
futex(0x7f4ae0000950, FUTEX_WAIT_PRIVATE, 0, NULL) = 0                                                                                                                                                                                                                                                                      
futex(0x7f4ae0000950, FUTEX_WAIT_PRIVATE, 0, NULL) = 0                                                                                                                                                                                                                                                                      
clone(child_stack=0x7f4ade7fbfd0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f4ade7fc9d0, tls=0x7f4ade7fc700, child_tidptr=0x7f4ade7fc9d0) = 12081                                                                
futex(0x16a7850, FUTEX_WAKE_PRIVATE, 1) = 1                                                                                                                                                                                                                                                                                 
futex(0x16a7850, FUTEX_WAKE_PRIVATE, 1) = 0                                                                                                                                                                                                                                                                                 
futex(0x16a7850, FUTEX_WAKE_PRIVATE, 1) = 0                                                                                                                                                                                                                                                                                 
futex(0x16a7850, FUTEX_WAIT_PRIVATE, 0, NULL) = -1 EAGAIN (Resource temporarily unavailable)                                                                                                                                                                                                                                
futex(0x7f4ae0000950, FUTEX_WAKE_PRIVATE, 1) = 1                                                                                                                                                                                                                                                                            
futex(0x7f4ae0012f20, FUTEX_WAIT_PRIVATE, 0, NULL) = 0                                                                                                                                                                                                                                                                      
futex(0x16a7850, FUTEX_WAIT_PRIVATE, 0, NULL) = 0                                                                                                                                                                                                                                                                           
futex(0x7f4ae0012f20, FUTEX_WAIT_PRIVATE, 0, NULL) = 0                                                                                                                                                                                                                                                                      
clone(child_stack=0x7f4ade7fbfd0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f4ade7fc9d0, tls=0x7f4ade7fc700, child_tidptr=0x7f4ade7fc9d0) = 12086                                                                
futex(0x7f4ae0000950, FUTEX_WAIT_PRIVATE, 0, NULL) = 0                                                                                                                                                                                                                                                                      
futex(0x7f4ae0000950, FUTEX_WAIT_PRIVATE, 0, NULL) = 0                                                                                                                                                                                                                                                                      
clone(child_stack=0x7f4ade7fbfd0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f4ade7fc9d0, tls=0x7f4ade7fc700, child_tidptr=0x7f4ade7fc9d0) = 12088                                                                
futex(0x7f4ae0012f20, FUTEX_WAIT_PRIVATE, 0, NULL) = 0                                                                                                                                                                                                                                                                      
futex(0x7f4ae0012f20, FUTEX_WAIT_PRIVATE, 0, NULL) = 0                                                                                                                                                                                                                                                                      
futex(0x16a7850, FUTEX_WAKE_PRIVATE, 1) = 1                                                                                                                                                                                                                                                                                 
futex(0x16a7850, FUTEX_WAKE_PRIVATE, 1) = 0                                                                                                                                                                                                                                                                                 
+++ killed by SIGSEGV +++
bok commented 12 years ago

Do you use version 1.6.1, released yesterday? It's a bugfix release which fixes a memory corruption bug. Also, the strace output is not really useful. It would be better if you could provide a gdb backtrace, obtained from a coredump.

wolph commented 12 years ago

Yes, I installed it yesterday :)

You're right, the strace output isn't that useful. I have enabled core dumps now so I can give you the dump (or backtrace). Do I need to recompile anything with debug flags enabled?

wolph commented 12 years ago

This backtrace seems somewhat less than useful ;)

#0  0x00007f689e7660e0 in ?? () from /usr/local/lib/libspotify.so.10
(gdb) backtrace
#0  0x00007f689e7660e0 in ?? () from /usr/local/lib/libspotify.so.10
#1  0x00007f689e766805 in ?? () from /usr/local/lib/libspotify.so.10
#2  0x00007f689e6f53b3 in ?? () from /usr/local/lib/libspotify.so.10
#3  0x00007f689e8052bc in ?? () from /usr/local/lib/libspotify.so.10
#4  0x00007f689e8056d9 in ?? () from /usr/local/lib/libspotify.so.10
#5  0x00007f68a02b5efc in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
#6  0x00007f689f14d89d in clone () from /lib/x86_64-linux-gnu/libc.so.6
#7  0x0000000000000000 in ?? ()
(gdb) quit
bok commented 12 years ago

Do you call any Spotify API function from the following Session callbacks?

end_of_track, music_delivery, notify_main_thread

They are called from an internal libspotify thread, and libspotify is not thread-safe (I'm working on a pyspotify fix).

wolph commented 12 years ago

The end_of_track method automatically adds the next song to the queue, could that be the problem?

bok commented 12 years ago

Yes, we have the same problem with our jukebox example. For now, the workaround is to add the next song from the main thread (the one running the session manager), so you'll need to have proper synchronization in your app.

wolph commented 12 years ago

Ok, thank you for the info :)