xbianonpi / xbian

XBMC on Raspberry Pi, Bleeding Edge
https://xbian.org
GNU General Public License v3.0
294 stars 44 forks source link

Upstart bridge fails when using profiles without autologin #728

Open RabidArts opened 9 years ago

RabidArts commented 9 years ago

Hi all

I had this situation with a kodi installation, specifically with profiles set up, and no auto-login.

Kodi would throw an error on startup (onscreen) saying that the xbian upstart bridge script failed. Following that, a number of other things in kodi are unstable - I would get random reboots. This is likely due to memory leaks.

I have already fixed the issue on my system, and am contributing the cause and solution to the community.

Investigation:

In the kodi log (~/.kodi/temp/kodi/log) you will find that the upstart bridge script fails on line 119.

Example kodi log error:

ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                         - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                        Error Type: <type 'exceptions.KeyError'>
                                        Error Contents: ('result',)
                                        Traceback (most recent call last):
                                          File "/usr/local/share/kodi/addons/script.service.xbian.upstart-bridge/service.py", line 202, in <module>
                                            service = UpstartBridge()
                                          File "/usr/local/share/kodi/addons/script.service.xbian.upstart-bridge/service.py", line 20, in __init__
                                            self.monitor = XBMCMonitor(self)
                                          File "/usr/local/share/kodi/addons/script.service.xbian.upstart-bridge/service.py", line 120, in __init__
                                            json_version = json_response['result']['version']
                                        KeyError: ('result',)
                                        -->End of Python script error report<--

Looking on line 119 you find the following:

    # This should never fail
    json_response = json.loads(xbmc.executeJSONRPC('{"jsonrpc": "2.0", "id": "ApiVersion", "method": "JSONRPC.Version"}'))
    json_version = json_response['result']['version']
    self.jsonrpc_api_ver = (json_version['major'], json_version['minor'], json_version['patch'])

If you log the return value from JSONRPC, you'll find that it says 'Method not found'

BTW, the This should never fail comment really cracked me up. Nice one Anaconda! :D (https://github.com/xbianonpi/xbian-package-upstart-xbmc-bridge/commit/de89836e2578ba4f1d18123bdba7d534e7df3b33)

_TL;DR: _

Cause:

The JSON RPC service is not started when xbian starts, only once you log in. If you have multiple profiles, well, you can guess the rest.

Solution:

Change the xbian upstart script to run on login, not on startup.

How, you say? sudo nano /usr/local/share/kodi/addons/script.service.xbian.upstart-bridge/addon.xml Find the line with:

     <extension point="xbmc.service" library="service.py" start="startup"/>

Replace start="startup" with start="login" Save, reboot, celebrate, profit!

Confirmation:

I logged out the response from JSONRPC.Version in the xbian upstart script - result is: XBian XBMC-Upstart bridge: JSON RPC Version Response: { " i d " : " A p i V e r s i o n " , " j s o n r p c " : " 2 . 0 " , " r e s u l t " : { " v e r s i o n " : { " m a j o r " : 6 , " m i n o r " : 2 1 , " p a t c h " : 2 } } }

RabidArts commented 9 years ago

Update: I'm experiencing a potential side effect of this solution - sometimes I have to log in twice. Possibly a race condition on the upstart script when set to run on login, and some other part of the system.

This doesn't bother me a lot, but obviously a problem for a stable build release.

I'll have a look at the logs and see if I can resolve it or at least get more information.

Possible solutions that come to mind:

  1. Upstart on startup, but delay json rpc calls until login.
  2. Find the script that crashes on login, and make it more resilient by , e,g, waiting and retrying
Smultie commented 9 years ago

I don't use any profiles, and XBian has been throwing me the same error since a couple of updates, but the solution you posted isn't helping in my situation.

Thanks for trying to fix it, though!!

RabidArts commented 9 years ago

Must be a different reason in your case... Could you link us a pastebin of your kodi log? On 18 May 2015 13:29, "Smultie" notifications@github.com wrote:

I don't use any profiles, and XBian has been throwing me the same error since a couple of updates, but the solution you posted isn't helping in my situation.

Thanks for trying to fix it, though!!

— Reply to this email directly or view it on GitHub https://github.com/xbianonpi/xbian/issues/728#issuecomment-103024493.

Smultie commented 9 years ago

Sure, see below: http://pastebin.com/iNu0kBAY

RabidArts commented 9 years ago

Update: Haven't had a chance to look again yet - hope to try looking at it tomorrow. However in your case (Smultie), I can see the line numbers are a bit different, so as I suspected, it's unlikely to be the same issue.

RabidArts commented 9 years ago

Smultie: I had a look at the code to work out where your problem is, but your version of the usptart bridge addon appears to be quite different. It's either custom-modified or very old - I cannot find your version anywhere online.

My advice - uninstall and reinstall the upstart bridge from the xbian config dialog on ssh login. But this is just my suggestion as an amateur - use at your own risk :)

Smultie commented 9 years ago

Yeah, might be something I should've told you from the start; I'm running XBian on Jessie. http://apt1.xbian.org/pool/stable/rpi2-jessie/ and http://apt1.xbian.org/pool/staging/rpi2-jessie/

On Thu, May 28, 2015 at 7:10 PM, RabidArts notifications@github.com wrote:

Smultie: I had a look at the code to work out where your problem is, but your version of the usptart bridge addon appears to be quite different. It's either custom-modified or very old - I cannot find your version anywhere online.

My advice - uninstall and reinstall the upstart bridge from the xbian config dialog on ssh login. But this is just my suggestion as an amateur - use at your own risk :)

— Reply to this email directly or view it on GitHub https://github.com/xbianonpi/xbian/issues/728#issuecomment-106495752.

RabidArts commented 9 years ago

Smultie: I can't seem to find the service.py file for the Jessie version.

Could you start a thread elsewhere (if you haven't already)? And in it post the content of the file /usr/local/share/kodi/addons/script.service.xbian.upstart-bridge/service.py

That way I can help advise you based on the actual code, and more importantly, give other (more knowledgeable) people in the forum a chance to answer :)

On Thu, May 28, 2015 at 7:19 PM, Smultie notifications@github.com wrote:

Yeah, might be something I should've told you from the start; I'm running XBian on Jessie. http://apt1.xbian.org/pool/stable/rpi2-jessie/ and http://apt1.xbian.org/pool/staging/rpi2-jessie/

On Thu, May 28, 2015 at 7:10 PM, RabidArts notifications@github.com wrote:

Smultie: I had a look at the code to work out where your problem is, but your version of the usptart bridge addon appears to be quite different. It's either custom-modified or very old - I cannot find your version anywhere online.

My advice - uninstall and reinstall the upstart bridge from the xbian config dialog on ssh login. But this is just my suggestion as an amateur - use at your own risk :)

— Reply to this email directly or view it on GitHub https://github.com/xbianonpi/xbian/issues/728#issuecomment-106495752.

— Reply to this email directly or view it on GitHub https://github.com/xbianonpi/xbian/issues/728#issuecomment-106502025.

RabidArts commented 9 years ago

In the pull request, mk01 says : "the needed "initctl emit xbmc-loaded" was moved directly into xbmc code, so non starting of this service (without login - in case of profiles) should not longer be an issue. or ?"

So gonna have a look sometime and try it out