Rails app with Spotify Gem works locally but segfaults on "production" server

108 views
Skip to first unread message

Gary Pinkham

unread,
Jun 1, 2014, 2:14:43 PM6/1/14
to ruby-s...@googlegroups.com
I now have the app only creating the session once (not sure how long that session is good for so need to investigate that)..   But locally I can login many times..  read playlists etc etc etc..   But when I deploy this to a server in production mode (Ruby 2.1.1, Rails 4.1.1, Ubuntu 12.04) it crashes trying to create the session..     here's the top part of the crash..

App 16045 stderr: /home/gpinkham/apps/beats-importer/shared/bundle/ruby/2.1.0/gems/spotify-12.5.3/lib/spotify.rb:101:
App 16045 stderr: [BUG]
App 16045 stderr: Segmentation fault at 0x00000000000230
App 16045 stderr:
App 16045 stderr: ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
App 16045 stderr:
App 16045 stderr: -- Control frame information -----------------------------------------------
App 16045 stderr: c:0085
App 16045 stderr: p:----
App 16045 stderr: s:0449
App 16045 stderr: e:000448
App 16045 stderr: CFUNC
App 16045 stderr:  :session_create
App 16045 stderr:
App 16045 stderr: c:0084
App 16045 stderr: p:0015
App 16045 stderr: s:0444
App 16045 stderr: e:000443
App 16045 stderr: BLOCK
App 16045 stderr:  /home/gpinkham/apps/beats-importer/shared/bundle/ruby/2.1.0/gems/spotify-12.5.3/lib/spotify.rb:101
App 16045 stderr:
App 16045 stderr: c:0083
App 16045 stderr: p:0014
App 16045 stderr: s:0442
App 16045 stderr: e:000441
App 16045 stderr: METHOD
App 16045 stderr:  /home/gpinkham/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/monitor.rb:211
App 16045 stderr:
App 16045 stderr: c:0082
App 16045 stderr: p:0009
App 16045 stderr: s:0439
App 16045 stderr: e:000438
App 16045 stderr: METHOD
App 16045 stderr:  /home/gpinkham/apps/beats-importer/shared/bundle/ruby/2.1.0/gems/spotify-12.5.3/lib/spotify.rb:100
App 16045 stderr:  [FINISH]
App 16045 stderr:
App 16045 stderr: c:0081
App 16045 stderr: p:----


Kim Burgestrand

unread,
Jun 1, 2014, 4:08:57 PM6/1/14
to Spotify for Ruby on behalf of Gary Pinkham
Segfaults are really hard to diagnose, but there's a hint in your output: App 16045 stderr:  :session_create — something is off when you create your session.

I would guess that how you configure your session is the problem.

— Kim Burgestrand


--
You received this message because you are subscribed to the Google Groups "Spotify for Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-spotify...@googlegroups.com.
Visit this group at http://groups.google.com/group/ruby-spotify.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-spotify/f9e3c4e0-80ab-49cb-98bf-8a4afe86a339%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gary Pinkham

unread,
Jun 1, 2014, 4:43:03 PM6/1/14
to ruby-s...@googlegroups.com
must be environment then..  its the same code that runs locally as the server..    and its pretty much the same init that is in the examples..  

    session ||= FFI::MemoryPointer.new(Spotify::Session) do |ptr|
      Rails.logger.info '###### Initializing the Spotify session ######'
      Spotify.try(:session_create, DEFAULT_CONFIG, ptr)
      break Spotify::Session.new(ptr.read_pointer)
    end



On Sunday, June 1, 2014 4:08:57 PM UTC-4, Kim Burgestrand wrote:
Segfaults are really hard to diagnose, but there's a hint in your output: App 16045 stderr:  :session_create — something is off when you create your session.

I would guess that how you configure your session is the problem.

— Kim Burgestrand

Kim Burgestrand

unread,
Jun 1, 2014, 4:48:34 PM6/1/14
to Spotify for Ruby on behalf of Gary Pinkham
Heroku has a read-only filesystem. If you use the default configuration from the example support, the cache directories are probably set to a directory that cannot be created.

I've run the spotify gem on Heroku before, so I know it works in that environment.

— Kim Burgestrand


Gary Pinkham

unread,
Jun 1, 2014, 5:21:39 PM6/1/14
to ruby-s...@googlegroups.com
it should be writable..    my default writes to the rails app's tmp directory..

  DEFAULT_CONFIG = Spotify::SessionConfig.new({
                                                  api_version: Spotify::API_VERSION.to_i,
                                                  application_key: File.binread(Rails.root.join('config', 'spotify_appkey.key')),
                                                  cache_location: Rails.root.join('tmp','.spotify/').to_s,
                                                  settings_location: Rails.root.join('tmp','.spotify/').to_s,
                                                  user_agent: 'spotify for ruby',
                                                  callbacks: Spotify::SessionCallbacks.new
                                              })

looked in the tmp/.spotify directory..  nothing was written..   its currently set to 777 to make sure anything can write to it..     I'll try another location and see what happens..  

On Sunday, June 1, 2014 4:48:34 PM UTC-4, Kim Burgestrand wrote:
Heroku has a read-only filesystem. If you use the default configuration from the example support, the cache directories are probably set to a directory that cannot be created.

I've run the spotify gem on Heroku before, so I know it works in that environment.

— Kim Burgestrand

Will Carter

unread,
Jun 2, 2014, 10:39:57 PM6/2/14
to ruby-s...@googlegroups.com
Gary,
Care to post what you are working on to github? You seem to be further along than me.
-Will

Gary Pinkham

unread,
Jun 3, 2014, 6:24:31 AM6/3/14
to ruby-s...@googlegroups.com
maybe once the code doesn't suck so much.. :-)       you can check it out here: www.beatsimporter.com     currently it supports converting csv and iTunes playlists to Beats Music Playlist..   Spotify (for the above reasons) does not work..    I plan to skip spotify and work on Rdio and Grooveshark next..   maybe come back to spotify if I have time to deal with it..

William Carter

unread,
Jun 3, 2014, 12:18:03 PM6/3/14
to Spotify for Ruby on behalf of Gary Pinkham
oh, i see. because you were talking about heroku, i thought you had something working in your local environment (further than me) but was trying to get it working in a production environment.
-will


--
You received this message because you are subscribed to the Google Groups "Spotify for Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-spotify...@googlegroups.com.
Visit this group at http://groups.google.com/group/ruby-spotify.

Gary Pinkham

unread,
Jun 3, 2014, 12:47:14 PM6/3/14
to ruby-s...@googlegroups.com
yeah definitely some confusion as I'm not using Heroku..     I have the spotify gem working in my local dev environment. . I can create a session, login, read playlists, read tracks from a playlist and import those tracks into Beats Music..     when I deploy to production (digitial ocean not Heroku) I can't even create a session without a seg fault..    i thought maybe it was a memory constraint to I bumped the memory on my vm to 1gb.. didn't help..

On Tuesday, June 3, 2014 12:18:03 PM UTC-4, Will Carter wrote:
oh, i see. because you were talking about heroku, i thought you had something working in your local environment (further than me) but was trying to get it working in a production environment.
-will

Will Carter

unread,
Jun 3, 2014, 5:23:51 PM6/3/14
to ruby-s...@googlegroups.com
Hi Gary,

Care to share your read playlists RoR web app code? All I was trying to do was execute the playlist example code in a controller method.

Here's the example vs. my welcome controller, index method.

I am just interested in Spotify at the moment. Maybe I could push ahead in that direction and figure it out. When you come back around to Spotify with your app, maybe I will have progressed and can share code to you.

thanks for any help or ideas you might be able to provide.

Will

Gary Pinkham

unread,
Jun 6, 2014, 1:48:47 PM6/6/14
to ruby-s...@googlegroups.com

I have been playing around with this constantly..    i have tried changing the directory of the cache a million different ways..   so not sure if that is what is causing the segfault..    I also changed the location of the api key file and the app failed to start completely not just when it tried to use the session..   so I know it could find the api key file before..   

I successfully ran one of the examples on the server outside of rails so I'm sure the libspotify library is functional..  just not from within Rails..   again this leads me to think it's my config but dammed if I can figure out what is wrong with it..

so I'm still no closer to solving this and moving onto Rdio integration..

Kim Burgestrand

unread,
Jun 6, 2014, 4:08:29 PM6/6/14
to Spotify for Ruby on behalf of Gary Pinkham
Not sure why I thought you used Heroku. Sorry about that.

I've had instant segfaults on session creation before, and reasons for that have been:

- invalid session configuration (most of the time) — application key being nil, some callback being set to nil, or something similar
- invalid spotify cache — sometimes forcefully killing the process will leave the cache directory in a bad state, and it needs to be removed
- running code on windows — most likely not your issue, since you're using ubuntu
- running the wrong distribution of libspotify

Have you been able to run any of the example code (https://github.com/Burgestrand/spotify/tree/master/examples) on your production machine? I'd start there, to see if that works first.

— Kim Burgestrand


--
You received this message because you are subscribed to the Google Groups "Spotify for Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-spotify...@googlegroups.com.
Visit this group at http://groups.google.com/group/ruby-spotify.

Gary Pinkham

unread,
Jun 6, 2014, 4:58:22 PM6/6/14
to ruby-s...@googlegroups.com
yes I ran one of the examples on the server but outside of rails.. so regular ruby command line..   I figured this meant the libspotify and spotify gem were functional.. and that it was in my code somewhere..    looking at your list that would cross of 3 and 4..   #2 is unlikely as it had never even created the cache on the server.. never got that far..  the .spotify directory that I pass in as part of the config is completely empty..     so that looks like #1 is the likely candidate..  again the directories should be writable..   the api key is there (when I removed the file the app couldn't even start up..)  as for the callbacks..  I set it to the same as the example.. (Spotify::SessionCallbacks.new)..  

I was thinking maybe the issue you mentioned in Will's thread about forks and passenger..  I am running in Passenger.. is the issue because each worker gets a session or is it something else?     not sure how else I would run the site without something like passenger or unicorn..

I already finished the Rdio integration, so I'm back onto this issue full time again..  :-)   



On Friday, June 6, 2014 4:08:29 PM UTC-4, Kim Burgestrand wrote:
Not sure why I thought you used Heroku. Sorry about that.

I've had instant segfaults on session creation before, and reasons for that have been:

- invalid session configuration (most of the time) — application key being nil, some callback being set to nil, or something similar
- invalid spotify cache — sometimes forcefully killing the process will leave the cache directory in a bad state, and it needs to be removed
- running code on windows — most likely not your issue, since you're using ubuntu
- running the wrong distribution of libspotify

Have you been able to run any of the example code (https://github.com/Burgestrand/spotify/tree/master/examples) on your production machine? I'd start there, to see if that works first.

— Kim Burgestrand

Kim Burgestrand

unread,
Jun 6, 2014, 5:00:26 PM6/6/14
to Spotify for Ruby on behalf of Gary Pinkham
Does it crash with passenger on your local computer too?

— Kim Burgestrand


Kim Burgestrand

unread,
Jun 6, 2014, 5:04:55 PM6/6/14
to Spotify for Ruby on behalf of Gary Pinkham
Oh, by the way, it sounds like you could also use https://github.com/liesen/spotify-api-server in case the spotify bindings in Ruby does not work out for you.

— Kim Burgestrand

Gary Pinkham

unread,
Jun 6, 2014, 5:50:46 PM6/6/14
to ruby-s...@googlegroups.com
that's pretty cool.. 

as for passenger locally.. I haven't tried it yet..  I will do that ASAP..  (I just run webrick locally)..

On Friday, June 6, 2014 5:04:55 PM UTC-4, Kim Burgestrand wrote:
Oh, by the way, it sounds like you could also use https://github.com/liesen/spotify-api-server in case the spotify bindings in Ruby does not work out for you.

— Kim Burgestrand

Gary Pinkham

unread,
Jun 7, 2014, 1:26:00 PM6/7/14
to ruby-s...@googlegroups.com
Passenger behind Nginx works locally as well..   its just the server that fails..  

Kim Burgestrand

unread,
Jun 7, 2014, 1:42:12 PM6/7/14
to Spotify for Ruby on behalf of Gary Pinkham
I don't think I can help you much more like this I'm afraid.

Could you make a minimal example that works locally, segfaults on DO, and put it up on GitHub? That way I can try it for myself.

Keep in mind that your Spotify username, password, and application key should remain secret. Do not give them to me, and do not put them on GitHub.


— Kim Burgestrand


Gary Pinkham

unread,
Jun 17, 2014, 6:30:02 PM6/17/14
to ruby-s...@googlegroups.com
BTW..  Spotify just released a new Web based API today..   I made the switch..     I will try to spend some time after things settle to debug the issue I had with the C library and let you know..    

Best,
Gary


On Saturday, June 7, 2014 1:42:12 PM UTC-4, Kim Burgestrand wrote:
I don't think I can help you much more like this I'm afraid.

Could you make a minimal example that works locally, segfaults on DO, and put it up on GitHub? That way I can try it for myself.

Keep in mind that your Spotify username, password, and application key should remain secret. Do not give them to me, and do not put them on GitHub.


— Kim Burgestrand

William Carter

unread,
Jun 17, 2014, 6:35:56 PM6/17/14
to Spotify for Ruby on behalf of Gary Pinkham

Sweet! I have not been able to get back to this yet (probably a good thing).
Thanks for the heads up!

Kim Burgestrand

unread,
Jun 18, 2014, 2:11:59 AM6/18/14
to Spotify for Ruby on behalf of Will Carter
Awesome! I have been waiting for this web API for like 4 years! :)

— Kim Burgestrand


Mathias Bruce

unread,
Jun 18, 2014, 9:34:22 AM6/18/14
to ruby-s...@googlegroups.com
I apologize for perhaps derailing this thread further, but... I have been waiting a LONG time for this web API too (using Hallon before and now Spotify's C-library directly from non-Ruby) but after looking at it I can't find a way to play entire tracks with this new web API. The only track audio data I can find is the 30s preview URL. Am I missing something or do they want to disallow building players using this API? Perhaps Spotify's C-library (and all bindings for it) will continue to be relevant for everyone building actual players.

-- Mathias

On Wednesday, June 18, 2014 8:11:59 AM UTC+2, Kim Burgestrand wrote:
Awesome! I have been waiting for this web API for like 4 years! :)

— Kim Burgestrand


On Wed, Jun 18, 2014 at 12:35 AM, Spotify for Ruby on behalf of Will Carter <ruby-s...@googlegroups.com> wrote:

Sweet! I have not been able to get back to this yet (probably a good thing).
Thanks for the heads up!

Kim Burgestrand

unread,
Jun 18, 2014, 1:38:34 PM6/18/14
to Spotify for Ruby on behalf of Mathias Bruce
They still need control of who can stream what and when, and that'll be tricky to do with the current state of web technologies. I suppose it's possible they might allow some kind of streaming in the future for authenticated requests, but I do think that libspotify will continue to be relevant for audio streaming.

It does a lot of things behind the covers in order to cache and prefetch audio, and store it in a safe way to prevent ripping the audio.

It also appears that the new web API does not have all the browsing capabilities of libspotify. They're promising to expand upon the new web API, so it's likely that libspotify will become more and more targeted for custom players. I've wanted to improve upon the Spotify gem's ability to play audio for about a year now, so it kind of fits nicely with what's going on with the gem. :)

— Kim Burgestrand


Reply all
Reply to author
Forward
0 new messages