Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpvshim auto reconnect issue with jellyfin 10.9 #390

Closed
miltuss opened this issue May 17, 2024 · 18 comments · Fixed by #393
Closed

mpvshim auto reconnect issue with jellyfin 10.9 #390

miltuss opened this issue May 17, 2024 · 18 comments · Fixed by #393
Labels
bug Something isn't working

Comments

@miltuss
Copy link

miltuss commented May 17, 2024

Describe the bug
mpvshim works well with version 10.8 but it does not work well with version 10.9 The first connection succeeds but reconnections fail because jellyfin refuses authentication. I noticed that there were two elements that changed in the mpvshim jellyfin session configuration file, the token and the time/date. Maybe the problem is related to the time and date. I tested mpvshim on two different machines under Linux and noticed the same problems!

To Reproduce
Steps to reproduce the behavior:

  1. use a version 10.9.x of jellyfin
  2. install mpvshim with pip or flatpak
  3. connect to jellyfin instance with mpvshim
  4. close mpvshim (kill the process)
  5. reopen mpv shim and jellyfin will refuse its four connection attempts

Expected behavior
That mpvshim automatically connects to jellyfin after a machine restart, mpvshim restart, or Jellyfin instance restart

Desktop (please complete the following information):

  • OS: [Linux-Mint Cinnamon]
  • Version [21.3]

Error Messages
Server Jellyfin

[23:13:03] [INF] [86] Emby.Server.Implementations.HttpServer.WebSocketManager: WS 192.168.0.10 request
[23:13:03] [INF] [13] Emby.Server.Implementations.HttpServer.WebSocketManager: WS 192.168.0.10 closed
[23:13:04] [INF] [85] Emby.Server.Implementations.HttpServer.WebSocketManager: WS 192.168.0.10 request
[23:13:04] [INF] [86] Emby.Server.Implementations.HttpServer.WebSocketManager: WS 192.168.0.10 closed
[23:13:05] [INF] [86] Emby.Server.Implementations.HttpServer.WebSocketManager: WS 192.168.0.10 request
[23:13:06] [INF] [87] Emby.Server.Implementations.HttpServer.WebSocketManager: WS 192.168.0.10 closed
[23:13:07] [INF] [86] Emby.Server.Implementations.HttpServer.WebSocketManager: WS 192.168.0.10 request
[23:13:07] [INF] [86] Emby.Server.Implementations.HttpServer.WebSocketManager: WS 192.168.0.10 closed

Client mpv-shim

2024-05-17 23:55:58,524 [    INFO] player: Using libmpv1 playback backend.
2024-05-17 23:55:58,540 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: Begin connect
2024-05-17 23:55:58,540 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: Begin getAvailableServers
2024-05-17 23:55:58,540 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: connect has 1 servers
2024-05-17 23:55:58,540 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: begin connect_to_server
2024-05-17 23:55:58,540 [    INFO] JELLYFIN.jellyfin_apiclient_python.api: Sending get request to system/info/public
2024-05-17 23:55:58,548 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: calling onSuccessfulConnection with server debian-nas
2024-05-17 23:55:58,549 [    INFO] JELLYFIN.jellyfin_apiclient_python.api: Sending get request to system/info
2024-05-17 23:55:58,553 [    INFO] JELLYFIN.jellyfin_apiclient_python.client: User is authenticated.
2024-05-17 23:55:58,554 [    INFO] JELLYFIN.jellyfin_apiclient_python.ws_client: Websocket url: ws://192.168.0.150:4042/socket?api_key=REDACTED&device_id=f2d13c4b-0016-462b-a4a9-b57894c3e326
2024-05-17 23:55:58,556 [    INFO] JELLYFIN.jellyfin_apiclient_python.ws_client: --->[ websocket ]
2024-05-17 23:55:58,567 [ WARNING] clients: Client is not actually connected. (It does not show in the client list.)
2024-05-17 23:55:58,717 [    INFO] JELLYFIN.jellyfin_apiclient_python.ws_client: ---<[ websocket ]
--<[ session/123210433516336 ]
2024-05-17 23:55:58,721 [    INFO] Jellyfin.jellyfin_apiclient_python.http: --<[ session/123210433516336 ]
2024-05-17 23:55:58,721 [ WARNING] clients: Partially connected. Retrying 1/3.
2024-05-17 23:55:59,723 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: Begin connect
2024-05-17 23:55:59,723 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: Begin getAvailableServers
2024-05-17 23:55:59,723 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: connect has 1 servers
2024-05-17 23:55:59,723 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: begin connect_to_server
2024-05-17 23:55:59,723 [    INFO] JELLYFIN.jellyfin_apiclient_python.api: Sending get request to system/info/public
2024-05-17 23:55:59,726 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: calling onSuccessfulConnection with server debian-nas
2024-05-17 23:55:59,726 [    INFO] JELLYFIN.jellyfin_apiclient_python.api: Sending get request to system/info
2024-05-17 23:55:59,728 [    INFO] JELLYFIN.jellyfin_apiclient_python.client: User is authenticated.
2024-05-17 23:55:59,728 [    INFO] JELLYFIN.jellyfin_apiclient_python.ws_client: Websocket url: ws://192.168.0.150:4042/socket?api_key=REDACTED&device_id=f2d13c4b-0016-462b-a4a9-b57894c3e326
2024-05-17 23:55:59,730 [    INFO] JELLYFIN.jellyfin_apiclient_python.ws_client: --->[ websocket ]
2024-05-17 23:55:59,896 [ WARNING] clients: Client is not actually connected. (It does not show in the client list.)
2024-05-17 23:55:59,904 [    INFO] JELLYFIN.jellyfin_apiclient_python.ws_client: ---<[ websocket ]
--<[ session/123206774349184 ]
2024-05-17 23:55:59,904 [    INFO] Jellyfin.jellyfin_apiclient_python.http: --<[ session/123206774349184 ]
2024-05-17 23:55:59,905 [ WARNING] clients: Partially connected. Retrying 2/3.
2024-05-17 23:56:00,906 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: Begin connect
2024-05-17 23:56:00,906 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: Begin getAvailableServers
2024-05-17 23:56:00,906 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: connect has 1 servers
2024-05-17 23:56:00,906 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: begin connect_to_server
2024-05-17 23:56:00,906 [    INFO] JELLYFIN.jellyfin_apiclient_python.api: Sending get request to system/info/public
2024-05-17 23:56:00,908 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: calling onSuccessfulConnection with server debian-nas
2024-05-17 23:56:00,908 [    INFO] JELLYFIN.jellyfin_apiclient_python.api: Sending get request to system/info
2024-05-17 23:56:00,911 [    INFO] JELLYFIN.jellyfin_apiclient_python.client: User is authenticated.
2024-05-17 23:56:00,911 [    INFO] JELLYFIN.jellyfin_apiclient_python.ws_client: Websocket url: ws://192.168.0.150:4042/socket?api_key=REDACTED&device_id=f2d13c4b-0016-462b-a4a9-b57894c3e326
2024-05-17 23:56:00,915 [    INFO] JELLYFIN.jellyfin_apiclient_python.ws_client: --->[ websocket ]
2024-05-17 23:56:00,936 [ WARNING] clients: Client is not actually connected. (It does not show in the client list.)
2024-05-17 23:56:00,942 [    INFO] JELLYFIN.jellyfin_apiclient_python.ws_client: ---<[ websocket ]
--<[ session/123206774341744 ]
2024-05-17 23:56:00,946 [    INFO] Jellyfin.jellyfin_apiclient_python.http: --<[ session/123206774341744 ]
2024-05-17 23:56:00,946 [ WARNING] clients: Partially connected. Retrying 3/3.
2024-05-17 23:56:01,947 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: Begin connect
2024-05-17 23:56:01,947 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: Begin getAvailableServers
2024-05-17 23:56:01,947 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: connect has 1 servers
2024-05-17 23:56:01,947 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: begin connect_to_server
2024-05-17 23:56:01,947 [    INFO] JELLYFIN.jellyfin_apiclient_python.api: Sending get request to system/info/public
2024-05-17 23:56:01,949 [    INFO] JELLYFIN.jellyfin_apiclient_python.connection_manager: calling onSuccessfulConnection with server debian-nas
2024-05-17 23:56:01,949 [    INFO] JELLYFIN.jellyfin_apiclient_python.api: Sending get request to system/info
2024-05-17 23:56:01,952 [    INFO] JELLYFIN.jellyfin_apiclient_python.client: User is authenticated.
2024-05-17 23:56:01,952 [    INFO] JELLYFIN.jellyfin_apiclient_python.ws_client: Websocket url: ws://192.168.0.150:4042/socket?api_key=REDACTED&device_id=f2d13c4b-0016-462b-a4a9-b57894c3e326
2024-05-17 23:56:01,954 [    INFO] JELLYFIN.jellyfin_apiclient_python.ws_client: --->[ websocket ]
2024-05-17 23:56:01,975 [ WARNING] clients: Client is not actually connected. (It does not show in the client list.)
2024-05-17 23:56:02,114 [    INFO] JELLYFIN.jellyfin_apiclient_python.ws_client: ---<[ websocket ]
--<[ session/123206774357728 ]
2024-05-17 23:56:02,119 [    INFO] Jellyfin.jellyfin_apiclient_python.http: --<[ session/123206774357728 ]

@miltuss miltuss added the bug Something isn't working label May 17, 2024
@iwalton3
Copy link
Member

I'm inclined to think this is a server issue. The "client not actually connected" is a check that MPV Shim does to try and make itself more robust against these failures.

@fredrik-eriksson
Copy link

I'm also seeing this, most likely the related upstream issue is this: jellyfin/jellyfin#11620. Seems like upgrading to the newly released 1.9.2 and/or configuring "Published Server URIs" (for reverse proxy setups?) may solve this.

@kartikynwa
Copy link

I am getting this issue on Windows with jellyfin-mpv-shim (v2.7.0) installed via scoop. When I "Add Server", it works fine. But if I restart the shim I get the same "Client is not actually connected" warning and it doesn't show up in the clients list.

On Linux, with shim installed via pipx, it works perfectly.

Jellyfin server is v10.9.2.

I will try installed shim on Windows from other sources and report back.

@dgalli1
Copy link

dgalli1 commented May 20, 2024

I am getting this issue on Windows with jellyfin-mpv-shim (v2.7.0) installed via scoop. When I "Add Server", it works fine. But if I restart the shim I get the same "Client is not actually connected" warning and it doesn't show up in the clients list.

On Linux, with shim installed via pipx, it works perfectly.

Jellyfin server is v10.9.2.

I will try installed shim on Windows from other sources and report back.

Can not confirm installed via pipx on arch linux and it doesn't work on a reconnect.

@fredrik-eriksson
Copy link

I'm also seeing this, most likely the related upstream issue is this: jellyfin/jellyfin#11620. Seems like upgrading to the newly released 1.9.2 and/or configuring "Published Server URIs" (for reverse proxy setups?) may solve this.

It wasn't possible for me to test at the time, but now I have tested, and it did not solve the problem for me.

There's another issue at home-assistant, home-assistant/core#117741, about sessions not being detected. Since both projects use the jellyfin-apiclient-python library there may be a common cause there somewhere?

@paindespik
Copy link

I'm also seeing this, most likely the related upstream issue is this: jellyfin/jellyfin#11620. Seems like upgrading to the newly released 1.9.2 and/or configuring "Published Server URIs" (for reverse proxy setups?) may solve this.

It wasn't possible for me to test at the time, but now I have tested, and it did not solve the problem for me.

There's another issue at home-assistant, home-assistant/core#117741, about sessions not being detected. Since both projects use the jellyfin-apiclient-python library there may be a common cause there somewhere?

Same, I tried every configuration I could think of, but cannot reconnect

@mcarlton00
Copy link
Member

So far we've been unable to reproduce this. I spent roughly an hour just stopping and starting mpv shim and had exactly 1 connection failure in 100+ attempts, and after the next restart it worked fine again. Both the native linux version and the flatpak version.

Are there any other similarities between folks who are experiencing issues?

  • How the server is installed?
  • What access method? (direct IP:Port of the server or through a reverse proxy)
  • Which reverse proxy (if any)?

@paindespik
Copy link

So far we've been unable to reproduce this. I spent roughly an hour just stopping and starting mpv shim and had exactly 1 connection failure in 100+ attempts, and after the next restart it worked fine again. Both the native linux version and the flatpak version.

Are there any other similarities between folks who are experiencing issues?

  • How the server is installed?
  • What access method? (direct IP:Port of the server or through a reverse proxy)
  • Which reverse proxy (if any)?

Since server update, I can not connect with the domain name, it seems to be unable to get response from socket, even on first try.
If I use IP:port, the first try works fine but not reconnect.
I use a nginx proxy with ssl and use the proposed nginx config on the jellyfin wiki.
I have tried different networking configuration in the settings page with no luck.
Jellyfin is installés with the install-debuntu.sh script on debian

@fredrik-eriksson
Copy link

* How the server is installed?

Server installed using the Gentoo ebuild.
Shim client is installed from source (2.7 release tarball, with minor patch to setup.py to remove default_shader_pack).

* What access method? (direct IP:Port of the server or through a reverse proxy)
* Which reverse proxy (if any)?

https to FQDN through two levels of reverse proxies (Internet ----https--> nginx (webfronted) ----https--> nginx (on jellyfin host) ----http--> jellyfin)

The nginx config is inspired by (but not identical to) the jellyfin nginx documentation as it was a year or two ago.

If it is of any help I use both Kodi plugins (Jellyfin for Kodi and JellyCon) as clients without any problems.

@Renvolt
Copy link

Renvolt commented May 22, 2024

So far we've been unable to reproduce this. I spent roughly an hour just stopping and starting mpv shim and had exactly 1 connection failure in 100+ attempts, and after the next restart it worked fine again. Both the native linux version and the flatpak version.

Are there any other similarities between folks who are experiencing issues?

* How the server is installed?

* What access method? (direct IP:Port of the server or through a reverse proxy)

* Which reverse proxy (if any)?

I have the server installed with docker using the official docker image(jellyfin/jellyfin). The issue started happening for me when I updated the image to the 10.9.2 version of jellyfin.

I have jellyfin-mpv-shim installed through the AUR on Arch Linux. I was using the previous version of the mpv-shim when the issue started and updating did not fix it. Assuming it had to be caused by the change on the jellyfin server's end.

I usually have it set to directly connect to the servers IP but I also tried connecting to it through NGINX proxy manager and got the same result.

As was mentioned by someone else, every time I launch the mpv-shim it fails to connect until it gives up then if I delete and re add the server it will connect fine on the first try and will work until I close the mpv-shim where I get the exact same behavior every time.

@krakow10
Copy link

krakow10 commented May 23, 2024

This issue is getting ridiculous for me - it started out where I had to run the command twice to get it to connect, but it seems to ~quadruple the number of reconnect attempts required every day I use it. Last week I modified the source code to reconnect 300 times, and since then it took 54 tries, then 220 tries, and now over 1000 to finally connect. I have not tried re-adding the server, may give that a go to see if I can avoid 4000 attempts tomorrow.

  • How the server is installed?

Installed from jellyfin ppa on a debian container in Proxmox

  • What access method? (direct IP:Port of the server or through a reverse proxy)

Direct IP:Port via an uninterrupted ethernet cable plugged in from desktop motherboard to server

  • Which reverse proxy (if any)?

None

@mcarlton00
Copy link
Member

I understand it's frustrating, but you have to realize that we're flying completely blind here. We can't reproduce the error, and by all indication things are being set up correctly and the server simply isn't responding with the proper data. I've tried both through reverse proxy and ip:port. I've set up a script to constantly start/kill the client. In hundreds of attempts, I've only seen one failure that immediately resolved itself. There's another factor in play that we haven't been able to identify.

I have 2 potential ideas. Neither of them seem very likely, but again, flying blind.

  • How many devices do you have set up in your jellyfin server? It's a possibility that the server is trying to match the current device to something in the list and struggling to parse how many there are (this seems very unlikely, but at this point nothing can be ruled out).
  • For those of you willing to tweak the source code, between these two lines:
    client.jellyfin.post_capabilities(CAPABILITIES)
    return self.validate_client(client)
    , add in a time.sleep(5). Or 10, or whatever value you're willing to wait. Again, this shouldn't really affect anything, but it gives the server more time to process before we attempt to validate the connection. But if you're getting that many retries, it's likely it's far exceeded this time and this won't help.

The only other option I can think of is to enable debug logging in the server and see if that gives more indication of there's a server error. https://jellyfin.org/docs/general/administration/troubleshooting#debug-logging

@fredrik-eriksson
Copy link

* For those of you willing to tweak the source code, between these two lines: https://github.com/jellyfin/jellyfin-mpv-shim/blob/9a6c1a8a718da6f3b806a4d049876f873515d946/jellyfin_mpv_shim/clients.py#L222-L223
  , add in a `time.sleep(5)`.  Or 10, or whatever value you're willing to wait.  Again, this _shouldn't_ really affect anything, but it gives the server more time to process before we attempt to validate the connection.  But if you're getting that many retries, it's likely it's far exceeded this time and this won't help.

Thank you, this was spot on (although I added a sleep for 1 second first line in validate_client()). I guess we who have this problem have servers that are too slow to populate the client list before the verification?

@paindespik
Copy link

* For those of you willing to tweak the source code, between these two lines: https://github.com/jellyfin/jellyfin-mpv-shim/blob/9a6c1a8a718da6f3b806a4d049876f873515d946/jellyfin_mpv_shim/clients.py#L222-L223
  , add in a `time.sleep(5)`.  Or 10, or whatever value you're willing to wait.  Again, this _shouldn't_ really affect anything, but it gives the server more time to process before we attempt to validate the connection.  But if you're getting that many retries, it's likely it's far exceeded this time and this won't help.

Thank you, this was spot on (although I added a sleep for 1 second first line in validate_client()). I guess we who have this problem have servers that are too slow to populate the client list before the verification?

yes works

@Renvolt
Copy link

Renvolt commented May 23, 2024

I found I did have a lot of devices built up on my server but clearing them out made no difference.

After adding even a 1 second sleep as suggested it now will connect every time and I haven't been able to get it to fail so far.

@krakow10
Copy link

adding this to the source code works for me as well:

client.jellyfin.post_capabilities(CAPABILITIES)
time.sleep(1)
return self.validate_client(client)

@mcarlton00 Sorry about using the phrase "this is getting ridiculous", that was a poor choice of words on my part, I meant that the amount of retries was ridiculous. I also didn't read your messages that clearly say you can't reproduce the issue, I know what that's like. No ill will from me ❤️

@ArdianaLeek
Copy link

client.jellyfin.post_capabilities(CAPABILITIES)
time.sleep(1)
return self.validate_client(client)
also fixed it for me

@miltuss
Copy link
Author

miltuss commented May 26, 2024

@mcarlton00 I was right and you were wrong. There is indeed a problem with 10.9 in terms of authentication. Because 10.8 does not suffer from this problem at all ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants