chorus2 icon indicating copy to clipboard operation
chorus2 copied to clipboard

Lost Websocket Connection

Open namirda opened this issue 8 years ago • 22 comments

Using Chorus2 with kodi 17.1 gives the following error in the browser every couple of minutes:

Lost Websocket Connection Attempting Websocket reconnect

At each reconnection, the following lines are received at the console ...

` SCRIPT12008: WebSocket Error: Incorrect HTTP response. Status code 200, OK %c Failed to connect to websockets, so I am falling back to polling for updates. Which makes things slower and uses more resources. Please ensure you have 'Allow programs on other systems to control Kodi' ENABLED in the Kodi settings (System > Services > Remote control). You may also get this if you are using proxies or accessing via an IP address when localhost will suffice. If websockets normally works, you might just need to refresh your browser. background: #FFFDD9; padding: 0 5px; color: #444; font-weight: bold; font-size: 110% [object Event] { [functions]: , proto: { }, AT_TARGET: 2, bubbles: false, BUBBLING_PHASE: 3, cancelable: false, cancelBubble: false, CAPTURING_PHASE: 1, constructor: { }, currentTarget: { }, defaultPrevented: false, eventPhase: 2, isTrusted: true, srcElement: { }, target: { }, timeStamp: 1494316718657, type: "error" }

%c Websockets Closed background: #FFFDD9; padding: 0 5px; color: #444; font-weight: bold; font-size: 110% [object CloseEvent] { [functions]: , proto: { }, AT_TARGET: 2, bubbles: false, BUBBLING_PHASE: 3, cancelable: false, cancelBubble: false, CAPTURING_PHASE: 1, code: 1006, constructor: { }, currentTarget: { }, defaultPrevented: false, eventPhase: 2, isTrusted: true, reason: "", srcElement: { }, target: { }, timeStamp: 1494316718664, type: "close", wasClean: false }

`

This error has also been reported here

The error occurs regardless of browser (IE11, Firefox and Chrome tried) and using Windows and Ubuntu as kodi host.

Any ideas?

Thanks

Neil

namirda avatar May 09 '17 08:05 namirda

Also here on my rpi3 with LibreElec 8.1.0 (Kodi 17.4). Tried to change the Webserver port to 80 but no change (read it somewhere that it can be help).

Dont know how to get this log above, but i inspect now the zipped logs.

Cris-- avatar Aug 21 '17 17:08 Cris--

Any news on this?

asm0dey avatar Apr 20 '19 08:04 asm0dey

Sadly none - and the problem still exists on Kodi 18.1.

And it's well beyond my capabilities to dive into it.

N

namirda avatar Apr 20 '19 08:04 namirda

Neil,

I had the same issue and bumped into this thread. Have you checked that you have enabled remote control like the error message suggests? That resolved the issue for me.

Please ensure you have 'Allow programs on other systems to control Kodi' ENABLED in the Kodi settings (System > Services > Remote control)

kevinrigney avatar Dec 31 '19 05:12 kevinrigney

Ditto, same issue here. And yes, of course 'Allow programs on other systems to control Kodi' is set. I wouldn't be using Chorus at all if not. And I checked to be sure, no surprise, it is. I'm using Chorus fine, it just pops up this stupid message every few minutes.

bernd-wechner avatar Mar 04 '20 07:03 bernd-wechner

I run into the same problem and could solve it.

Make sure that your firewall is allowing incoming traffic for the EventServer listening on the UDP port 9777 (this is the default port as seen in your 'guisettings.xml' file in 'userdata' folder). See https://kodi.wiki/view/EventServer#Event_Clients_and_the_EventServer

Make sure that your firewall is allowing incoming traffic for the JSON-RPC API listening on the TCP port 9090 by default. See https://kodi.wiki/view/JSON-RPC_API#WebSocket If you ever changed this port in your 'advancedsettings.xml' file in 'userdata' folder (see https://kodi.wiki/view/Advancedsettings.xml#jsonrpc), then you also have to give the same value to 'socketsPort:' on line 31 at this time in the file 'kodi-webinterface.js' located in '/usr/share/kodi/addons/webinterface.default/js/' for Linux. Note that this file may be replaced and your change erased in case of Kodi update.

This also solved local party mode desync of track info reported in #348

DjZU avatar Apr 29 '20 18:04 DjZU

If you ever changed this port in your 'advancedsettings.xml' file in 'userdata' folder (see https://kodi.wiki/view/Advancedsettings.xml#jsonrpc), then you also have to give the same value to 'socketsPort:' on line 31 at this time in the file 'kodi-webinterface.js' located in '/usr/share/kodi/addons/webinterface.default/js/' for Linux. Note that this file may be replaced and your change erased in case of Kodi update.

Shouldn't Chorus2 read from advancedsettings.xml to avoid that problem? Is this on the dev roadmap?

zedrdave avatar May 15 '20 12:05 zedrdave

To answer my own question: modifying the code as suggested above, is actually not needed… Simply edit update the webSockets port field in the preferences for the web interface under /#settings/web

zedrdave avatar May 15 '20 12:05 zedrdave

To answer my own question: modifying the code as suggested above, is actually not needed… Simply edit update the webSockets port field in the preferences for the web interface under /#settings/web

Any chance you can provide some more explicit instructions and what's going on. I admit it's late, but I just read the recent posts and am clueless. I run Chorus on one machine and Kodi on another one the same LAN with precisely zero firewall between them. And yet websockets time out all the frigging time. Next to unusable. Ever single time i visit It have to reload the page and pray ...

bernd-wechner avatar May 15 '20 14:05 bernd-wechner

@zedrdave no addon is allowed to read from advancedsettings.xml, chorus is not an exception

enen92 avatar May 15 '20 15:05 enen92

@bernd-wechner In my very specific case, I modified advancedsettings.xml to specify my own port (instead of 9090) and therefore was replying to this comment regarding the way to configure Chorus2 accordingly.

In your case, I have no idea. But what I would try is:

  • Look at what the browser is telling you:
    • does it ever connect to the WebSocket, or not at all?
    • which host/port is it trying to connect on? does the port match?
    • does it work when you try connecting directly to the WS (eg through a Chrome add-on for WS testing)
  • Check if the port really is open on Kodi's side: sudo netstat -tpln | grep kodi. You should be seeing port 9090 (or another port if you configured it that way).

If the port is open on Kodi's side (and you have no firewall), and the browser truly is trying to call the right host and port: I have no idea what might be going wrong, but it sounds like a bug.

zedrdave avatar May 15 '20 15:05 zedrdave

@enen92 Yes, sorry: I was mainly replying to this, which seemed a very kludgy way to handle that bit of config. But I found the UI setting to change that, and it's perfectly fine.

zedrdave avatar May 15 '20 15:05 zedrdave

@bernd-wechner I don't know what is the /#settings/web that @zedrdave is referring to, but AFAIK every machine has its own firewall, at least should, and it applies to the local network. On which system are you running Kodi?

DjZU avatar May 15 '20 15:05 DjZU

@DjZU I was referring to the web interface's settings page (reachable through that URL), which is a much cleaner way to override the default port.

BTW: most typical linux installs do not have a firewall enabled by default (although if @bernd-wechner can confirm that the right port is open, and the web client is really connecting to it, then I'd agree firewall is most likely the answer).

zedrdave avatar May 15 '20 15:05 zedrdave

@zedrdave OK now I understand which setting you mean, I did try it, it works but it is not persistent that's the reason why I came to 'hacking' the .js file.

DjZU avatar May 15 '20 16:05 DjZU

I admit I'm a little confused by what's needed. So here's what I can say:

  1. I have Kodi running in a Linux Mint 19.3 box
  2. I run Chorus in a web browser on another machine on the LAN (my desktop), also Linux Mint 19.3.
  3. Kodi's web server is configured to listen to port 8080 and which it it does, and I connect to http://kodiserver.lan:8080 and have a Chorus web interface (which is not bad).
  4. The Chorus web page displays regular pop ups in lower right saying it lost connection to websocket and trying again.
  5. Checked open ports quickly:
$ sudo netstat -tpln | grep kodi
[sudo] password for polyphemus:        
tcp        0      0 0.0.0.0:1175            0.0.0.0:*               LISTEN      17208/kodi-x11      
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      17208/kodi-x11      
tcp        0      0 127.0.0.1:52307         0.0.0.0:*               LISTEN      17208/kodi-x11      
tcp6       0      0 :::8080                 :::*                    LISTEN      17208/kodi-x11     

Nothing listening on 9090.

I checked the Firefox console quickly on Chorus and indeed cycles of this reported on console:

Firefox can’t establish a connection to the server at ws://cyclops.lan:9090/jsonrpc?kodi. kodi-webinterface.js:20898:13
 Failed to connect to websockets, so I am falling back to polling for updates. Which makes things slower and uses more resources. Please ensure you have 'Allow programs on other systems to control Kodi' ENABLED in the Kodi settings (System > Services > Remote control). You may also get this if you are using proxies or accessing via an IP address when localhost will suffice. If websockets normally works, you might just need to refresh your browser. kodi-webinterface.js:555:13
error { target: WebSocket, isTrusted: true, srcElement: WebSocket, currentTarget: WebSocket, eventPhase: 2, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, … }
kodi-webinterface.js:557:22
 Websockets Closed kodi-webinterface.js:555:13
close { target: WebSocket, isTrusted: true, wasClean: false, code: 1006, reason: "", srcElement: WebSocket, currentTarget: WebSocket, eventPhase: 2, bubbles: false, cancelable: false, … }
kodi-webinterface.js:557:22

Here's what I configured in Kodi:

image

Is there somewhere else to turn on the websocket support? Or a log I can check at the Kodi end? Why is nothing listening on 9090 I wonder. Thanks, the learning so far has pointed me ina direction on this annoying issue at least! But I'm not understanding something here about 8080 vs 9090 ... (I mean I can infer one is for HTTP support the other exposes and API over a websocket but I see only config for 808 at the Kodi end and at teh CHorus end I can see both configurable and I see nothing listening on 9090).

Update: Removing the Kodi restriction:

$ sudo netstat -tanpu | grep ":9090"
[sudo] password for polyphemus:        
tcp6       0      0 :::9090                 :::*                    LISTEN      1/init              
tcp6       0      0 192.168.0.12:9090       192.168.0.11:59202      TIME_WAIT   -       

So for some reasons init has 9090 open and that begins to explain a lot. Kodi can't open it. Wonder what this is about? I can confirm that on a fresh Ubuntu 20.04 server I see exactly the same. On my client Mint system though:

tcp6       0      0 :::9090                 :::*                    LISTEN      1/systemd  

which is bizarre as one Min 193 system has 1/init listening and the other 1/systemd. Hmmm.

It's all tcp6 related so I imagine some stock standard IPv6 service runs on 9090 now? So Google further and blam I found it! I run cockpit on these machines of late:

https://cockpit-project.org/

And it uses 9090 and runs as a system service!

$ service cockpit status
● cockpit.service - Cockpit Web Service
   Loaded: loaded (/lib/systemd/system/cockpit.service; static; vendor preset: enabled)
   Active: active (running) since Sat 2020-05-16 11:48:01 AEST; 1s ago
     Docs: man:cockpit-ws(8)
  Process: 23733 ExecStartPre=/usr/sbin/remotectl certificate --ensure --user=root --group=cockpit-ws --selinux-type= (code=exited, s
 Main PID: 23734 (cockpit-ws)
    Tasks: 3 (limit: 4915)
   CGroup: /system.slice/cockpit.service
           └─23734 /usr/lib/cockpit/cockpit-ws

May 16 11:48:01 cyclops systemd[1]: Starting Cockpit Web Service...
May 16 11:48:01 cyclops systemd[1]: Started Cockpit Web Service.
May 16 11:48:01 cyclops cockpit-ws[23734]: Using certificate: /etc/cockpit/ws-certs.d/0-self-signed.cert

Which means indeed I need to configure Kodi to use another port! Brilliant. Your ideas and suggestion have steered me in the right direct of diagnostics. I had zero idea about port 9090!

bernd-wechner avatar May 16 '20 01:05 bernd-wechner

And it's solved. I fixed advancedsettings.xml a la:

https://kodi.wiki/view/Advancedsettings.xml#jsonrpc

By adding:

<jsonrpc>
    <compactoutput>false</compactoutput>
    <tcpport>9091</tcpport>
</jsonrpc>

, restarted Kodi - an unfortunate necessity so I lost my current playlist ;-)

and in Chorus on web settings I pointed it to 9091: image

And watching the Firefox console now:

 Websockets Active kodi-webinterface.js:555:13

Thanks ever so much for the pointers!

bernd-wechner avatar May 16 '20 02:05 bernd-wechner

Absolutely excellent. Corrected the lost web socket issue. Thanks for the posting the fix.

ClearlyDazed avatar Sep 22 '20 16:09 ClearlyDazed

Good work Bernd, this fix worked for me.

rlall23 avatar Jan 06 '21 19:01 rlall23

This can be closed

DjZU avatar Aug 06 '21 23:08 DjZU

I am having the exact same problem - periodic 'Lost websocket connection' messages - but these instructions did not fix it.

I am running the CoreELEC distribution of Kodi 19.3; I created the advancedsettings.xml file in /storage/.kodi/userdata/ and put this in it: false 9091

I also enabled remote control from other systems.

Then I restarted Kodi.

In my browser I opened the Kodi page which launched Chorus. In Chorus' 'Web Interface' page I changed the websockets port number to 9091 and saved my changes. The 'Lost websocket connection' message still pops up periodically. What have I missed, or what has changed since Bernd solved this 18 months ago?

The-QA-Geek avatar Dec 28 '21 01:12 The-QA-Geek

The 'Lost websocket connection' message still pops up periodically. But it reconnects most times after tuning the network settings. Ubuntu 18.0.4 Nextcloud 22

Do as root echo 'net.core.wmem_max=12582912' >> /etc/sysctl.conf echo 'net.core.rmem_max=12582912' >> /etc/sysctl.conf echo 'net.ipv4.tcp_rmem= 10240 87380 12582912' >> /etc/sysctl.conf echo 'net.ipv4.tcp_wmem= 10240 87380 12582912' >> /etc/sysctl.conf echo 'net.ipv4.tcp_window_scaling = 1' >> /etc/sysctl.conf echo 'net.ipv4.tcp_timestamps = 1' >> /etc/sysctl.conf echo 'net.ipv4.tcp_sack = 1' >> /etc/sysctl.conf echo 'net.ipv4.tcp_no_metrics_save = 1' >> /etc/sysctl.conf echo 'net.core.netdev_max_backlog = 9000' >> /etc/sysctl.conf

sysctl -p

smokingwheels avatar Mar 26 '22 06:03 smokingwheels

if this is still an issue for anyone, please re-open

malard avatar Jan 27 '24 22:01 malard