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

Logged Out Between Sessions [TVOS] #776

Open
JPKribs opened this issue May 16, 2023 · 61 comments
Open

Logged Out Between Sessions [TVOS] #776

JPKribs opened this issue May 16, 2023 · 61 comments
Labels
bug Something isn't working

Comments

@JPKribs
Copy link
Member

JPKribs commented May 16, 2023

I can't get this trigger 100% of the time but I think I narrowed it down to having multiple users on the AppleTV. Since adding another user profile on the AppleTV, all saved Jellyfin users will get wiped after the TV goes to sleep or reboots.

I believe this is related to how session data is stored since this only started once I added other users. On another AppleTV, I have a single user and I have not experienced this issue (yet). I could be totally off base but if my guess is right I think this could be resolved by:

#661

#258

@extraslute
Copy link

I have experienced being logged out on a daily basis on my Apple TV 4K regardless of if there are multiple users or not. This doesn’t happen on my android tv nor any Rokus.

@JPKribs
Copy link
Member Author

JPKribs commented May 18, 2023

I haven't experienced this with multiple tvOS users. However, I haven't added more than one Jellyfin user.

The multiple TVOS users could be a red herring. That's just when I started seeing it. I know other people who get this regardless of TVOS users.

Is there a way to collect TVOS logs that I could help look at/provide to better understand this?

@LePips
Copy link
Member

LePips commented May 18, 2023

Sadly no logs would help, but I can investigate.

@JPKribs
Copy link
Member Author

JPKribs commented May 18, 2023

Sadly no logs would help, but I can investigate.

Thank you! I don't know if it changes anything but it's a 2nd Gen 4K

Since there is one that was impacted and one that is not, I've been racking my brain thinking what the difference between them could be. The only other thing I could think of is that the one that gets logged out also has Infuse logged into the same server. I'm not sure how that would make a difference. Just hoping maybe something there might help!

@JPKribs JPKribs changed the title Multiple Users - Logged Out Between Sessions [TVOS] Logged Out Between Sessions [TVOS] May 24, 2023
@IceHawk66
Copy link

I have experienced being logged out on a daily basis on my Apple TV 4K regardless of if there are multiple users or not. This doesn’t happen on my android tv nor any Rokus.

I'm facing the same error on my apple tv 4k. Logged in yesterday (again) and I have no server today. Have to enter server + credentials again.

@marvagabi
Copy link

I have the same issue as well, have Swiftfin installed on 3 apple tv's with accounts for myself my wife and my kids and it seems almost daily the accounts get wiped and I have to reconnect to the server and login again.

@Great-beaver
Copy link

The same issue. Can we help to investigate it somehow?

@LePips LePips added the bug Something isn't working label Jun 9, 2023
@bombyy
Copy link

bombyy commented Jun 11, 2023

Same issue for me.
My partner has an AppleTV 4K (1st Gen) and we basically get logged out every day.

@Raphty
Copy link

Raphty commented Jun 13, 2023

Thanks for this great tvOS app, but yes I have the same issue as the other on my 1st gen 4k

@LePips
Copy link
Member

LePips commented Jun 13, 2023

Apologies that I haven't been able to investigate, I see that this is a pressing issue. I'll take a look at this soon.

@dannycab
Copy link

This occurs on each Apple TV that I have of various models. It's too bad because Swiftfin is miles faster to load and navigate compared to Infuse. Just a better app IMO.

@adavidzh
Copy link

adavidzh commented Jul 2, 2023

I’m observing the same thing.
Is there information needed to help debug this?

@amochkin
Copy link

amochkin commented Jul 9, 2023

Same thing. Server shows multiple logged in sessions from that box. Apple TV 4K.

@pumax15
Copy link

pumax15 commented Jul 18, 2023

I’m still having this same issue as well. App is great, but frustrating constantly having to input credentials over and over.

@jshwrner
Copy link

Same problem, I have to sign in each time I open the app. I'm using the following:

AppleTV
Model: A1625
tvOS: 16.5

Jellyfin
Version: 10.8.3
Operating System: Linux
Architecture: X64

@IzaacJ
Copy link

IzaacJ commented Jul 30, 2023

Same issue here on our 4K 1st Gen On 16.5. We have multiple AppleIDs on it, but mainly using my AppleID, and we also have 6 users configured in Jellyfin.
Server info:
Version: 10.8.10
Operating System: Linux
Architecture: x64

@douglasparker
Copy link

Family members are also experiencing this bug! Looking forward to a resolution!

@Esthreel
Copy link

Esthreel commented Aug 4, 2023

I have the same issue. My login / server info is not being saved on tvOS. Any suggestions?

@extraslute
Copy link

I'd like to comment on here that I've continued to experience this for several months. Jellyfin kicks off any users signed into an Apple TV after 1 day and sometimes even after a few hours. It's hot and miss. Doesn't sign out any Rokus, Android TVs, or iOS devices though.

@KurzweilTV
Copy link

Just adding a +1 here. I don't know of any specific trigger, but I know I won't stay logged in for more than a day or so at most.

@LePips LePips pinned this issue Aug 8, 2023
@jet082
Copy link

jet082 commented Aug 9, 2023

Adding my voice in too! Relatives can't use the service at all because of the daily login requirement.

@ScoobyDoo27
Copy link

I am having the same issue as well. I am using a 1st and 2nd gen Apple TV 4K and my server is installed via docker on a NAS.

@iinkfish
Copy link

Happens with me too. It's just with one account though, after a certain period of time, usually a day, get logged out and I have to enter everything again including the ip address/domain

@Nicxe
Copy link

Nicxe commented Sep 2, 2023

Same here, I need to add a server and log in every time.

@BDub38
Copy link

BDub38 commented Sep 10, 2023

Glad to find this issue....this has been driving me crazy and I couldn't figure out what the issue was. Hoping to see a fix soon!!

@ghost
Copy link

ghost commented Sep 11, 2023

For anyone experiencing issues how have you logged in? I used to have this issue when logging in with a password but after I logged in with quick connect a few days ago it's been working fine (so far...).

@adavidzh
Copy link

I can’t do quick connect either. I run my server through docker and I believe that is the reason it doesn’t show up in the list of servers.

FWIW, my Jellyfin runs inside docker, shows up in the list of servers, and Quick Connect works. It's just not all that quick. (A QR code would be quicker.)

Still, the best would be for the credentials from logging in would be kept.

@Raphty
Copy link

Raphty commented Sep 15, 2023

I did try the "quick" login... it did not help. Next day I was logged out again. also I have to say that there is nothing quick about this... If you use a pw manager and your iphone to automatically put in the details that is 100times faster

still I have to say, I love the app!!! and I am super thankful ❤️

@JamesDearlove
Copy link

JamesDearlove commented Sep 16, 2023

This issue finally got to me and I had some free time, so I went hunting to see if I could track down what is causing this and I might have found the problem.

CoreStore stores its SQLite db in the caches directory on tvOS by default (CoreStore doc link) and I think this gets swept up when tvOS does a cleanup when running low on space. There's no nice way to trigger this cleanup in the Simulator from what I understand, so I've deployed a fix onto my Apple TV and will see if this does actually fix it.

I've committed a patch to my fork. If this fixes it, I'll open a PR.

Edit: This is an entire thing with data and caching in tvOS, I don't understand this well enough to fix it but Apple details bits of it in App Programming Guide for tvOS

@LePips
Copy link
Member

LePips commented Sep 17, 2023

Hey all, I've started debugging this and currently trying to replicate. If it is truly something that happens over a period of 24 hours, this might be tough.

@extraslute
Copy link

It is definitely something that happens over a 24 hour period. Probably the absolute most annoying thing I’ve ever experienced. And since my Jellyfin server is also part of my home assistant, every single time I have to login it creates a new “device” in home assistant so I have probably 60 Apple TVs showing but 59 of them inactive. I quit deleting them because it just continues to happen.

On my bedroom Sony Bravia for the AndroidTV app I haven’t ever been signed out.

If there's anything I can do to help you out let me know.

@Raphty
Copy link

Raphty commented Sep 18, 2023

I am not familiar with iOS/tvOS development, but I can help as well.

and interesting thing I had the last couple of days: when I have a video open when I leave the app, it keeps that video open over night, and I don't have to log in again (most days) but when I go back to the swiftfin overview, i think I am always logged out next evening (22h later most days 😃 )

@amochkin
Copy link

Apparently the issue can be fixed by using UserDefaults for storing API key.

@ghost
Copy link

ghost commented Sep 18, 2023

Using quick connect does not solve the problem.

As @JamesDearlove and @amochkin pointed out it seems like tvOS is very aggressive with purging data.

Moreover, your app can only access 500 KB of persistent storage that is local to the device (using the NSUserDefaults class). Outside of this limited local storage, all other data must be purgeable by the operating system when space is low.

That appears to be explaining why I'm not logged out of my Apple TV (as I don't use it too much) while someone I know is logged out much more often (and they use it a lot more). As far as I can see in the code the API key and the server details are not stored in UserDefaults so they are eligible for cleanup.

@LePips
Copy link
Member

LePips commented Sep 18, 2023

API keys are not stored in UserDefaults and never should be. I'm not too concerned with the cleanup being a problem as that is something that should have been an issue a long time ago, but it isn't out of the picture.

@amochkin
Copy link

API keys are not stored in UserDefaults and never should be. I'm not too concerned with the cleanup being a problem as that is something that should have been an issue a long time ago, but it isn't out of the picture.

I disagree, using UserDefaults completely solves the problem.
Can you please elaborate on why the app should never store API keys in UserDefaults?

@Raphty
Copy link

Raphty commented Sep 19, 2023

2 days in a row I was not logged out while I keep the next video on pause and not Return to the main screen - but last night I did go back so I can report tomorrow if I got logged out again 😅

@Raphty
Copy link

Raphty commented Sep 24, 2023

Have not been logged out since the new tv os update. Maybe that fixed it?

@JPKribs
Copy link
Member Author

JPKribs commented Sep 25, 2023

Using quick connect does not solve the problem.

As @JamesDearlove and @amochkin pointed out it seems like tvOS is very aggressive with purging data.

Moreover, your app can only access 500 KB of persistent storage that is local to the device (using the NSUserDefaults class). Outside of this limited local storage, all other data must be purgeable by the operating system when space is low.

That appears to be explaining why I'm not logged out of my Apple TV (as I don't use it too much) while someone I know is logged out much more often (and they use it a lot more). As far as I can see in the code the API key and the server details are not stored in UserDefaults so they are eligible for cleanup.

Following up on this being a purging data on low storage, I was able to successfully recreate this issue.

I have a few thousand photos in iCloud. When I remove iCloud Photos from syncing to the Apple TV, I have a lot of free space and I rarely have Swiftfin logouts. When I re-enable iCloud Photos to sync, the Apple TV downloads images to get me to ~1gb free. The next time I open Swiftfin it requires me to log back in.

I assume this would work with anything that takes up a lot of storage on the AppleTV. I've found Infuse likes to chew up storage room too and I experience the same issue when Infuse takes up >5gb of library images. In testing, it looks like when Swiftfin is not in the foreground and storage is low, credentials are lost.

I hope this helps in testing/troubleshooting! Hopefully others are able to recreate this as well.

Edit for context:

To identify the amount of storage used, I used this app: https://apps.apple.com/us/app/tv-info/id1443395433. So, a lot of this is riding off of the assumption that this app is accurate. I have a 32gb model and without Infuse/Photos I sit around 20gb in use. This number seems to fluctuate ~10gb without installing anything. I have found that it can even get to ~1gb left without adding anything new. I'm not an expert, but I would guess that Apple is pretty aggressive about caching? That being said, >1gb remaining, seems to be the sweet spot when it clears my login. When I get logged out, I found that Infuse also gives me that warning that it had to clear cached information. I hope this helps! Additionally, it would be great to confirm someone else was able to replicate this as well!

@jesuslopezreynosa
Copy link

I can replicate that the issue on tvOS 17 persists, and there is a new behaviour where it no longer accepts my credentials to log back into my media server.

@Nicxe
Copy link

Nicxe commented Oct 1, 2023

I can replicate that the issue on tvOS 17 persists,

Same here, is seams to work for me know on TvOs17. Haven't ben logoed ut for a couple of days now

@extraslute
Copy link

extraslute commented Oct 13, 2023

This issue has seemingly disappeared on both of my Apple TVs. Gen 2 and 4 after the last time I did an update (Ubuntu). Both are also on TVOS 17. Used to kick me out every day -- does not do this anymore.

@pumax15
Copy link

pumax15 commented Oct 13, 2023

I updated to the latest TV Os 17 and I still have the same problem. It keeps me logged in a little longer, but I still have to keep re-entering credentials.

@ioslife
Copy link

ioslife commented Oct 19, 2023

This problem made me switch to Infuse. I'd love to go back to Swiftfin, but this makes it unusable

@ioslife
Copy link

ioslife commented Oct 19, 2023

API keys are not stored in UserDefaults and never should be. I'm not too concerned with the cleanup being a problem as that is something that should have been an issue a long time ago, but it isn't out of the picture.

I disagree, using UserDefaults completely solves the problem. Can you please elaborate on why the app should never store API keys in UserDefaults?

API keys are typically considered private keys. UserDefaults stores data in a text file on the device. https://stackoverflow.com/questions/68022172/why-is-using-userdefaults-to-store-sensitive-information-on-ios-not-safe

@extraslute
Copy link

After updating to TVOS 17.1 -- this issue has came back. Logging out every single day at some point.

@zandr
Copy link

zandr commented Nov 22, 2023

Is there a workaround that I'm missing here? I'm not sure how this isn't a showstopper. I haven't been able to configure a user that doesn't require a login, which disappears in a day or so.

@LePips
Copy link
Member

LePips commented Nov 22, 2023

Sadly there isn't a workaround. Frankly, this issue has been difficult for me because:

  • I can barely reproduce it and I can't have a debugger (my laptop) running for days until I catch it
  • I don't watch much nowadays so my server is barely on
  • right now I'm more focused on getting iOS back to a state of release/polish because that's more manageable

So this issue is in the background for me, even though it can make the app practically unusable. I apologize for the inconvenience.

@zandr
Copy link

zandr commented Nov 22, 2023

Thanks for the quick response! I was hoping there was some way to get an account to show up in the "Public Users" side of the login screen or similar, but it's not clear how to do that.

I've done exactly no tvOS development, but if you can point me at a guide to running the debugger, I actually could hang a spare machine off of one of our AppleTVs.

@Raphty
Copy link

Raphty commented Nov 23, 2023

Have not been logged out since the new tv os update. Maybe that fixed it? (sep. 24th)

Since then I never got logged out again.

Maybe it is a different issue.

@imperialjoy
Copy link

Still happens to me. Is there a way to use jellyfin in DLNA mode without logging in? Is there a different way to store user credentials? Or setup Jellyfin to not need credentials? Seems like overkill for a LAN connection to the media server right beside the ATV.

@BDub38
Copy link

BDub38 commented May 7, 2024

It has been some time since the last comment on this thread. Has there been any progress or updates regarding this issue? I am still experiencing this. Sometimes it is daily or many days between the need to log in again.

@JPKribs
Copy link
Member Author

JPKribs commented May 10, 2024

This isn't a perfect fix, but it appears to happen when storage is low on the Apple TV. If you turn off the download screensaver option in the Apple TV settings and stop iCloud photos from syncing to the TV, it prevents the issue from occurring on my end. When I was doing some research it it sounds like Apple has a pretty aggressive cleanup process when storage starts getting low and Apple prioritizes retaining data from their own apps over third-party apps from the store so things like Infuse and Jellyfin have issues where the data gets wiped.

That being said, I think Jellyfin might be able to resolve this by moving how the credentials are stored? But I am absolutely not an expert, so I'll lean on more qualified people.

@RespectIsEverything
Copy link

Unaware if this issue is holding up the 1.1 update for tvos. I suspect most people would rather gain the updated device profile & pushback this bugfix for 1.2.

@PhilippeWeidmann
Copy link

Hi,

I took a look at this issue since I'm also having it on my Apple TV 😬
It is fairly easy to reproduce in a simulator:

  • Log the CoreStore location:
    For example in setupDataStack -> Container.shared.logService().info("Created store @ \(storage.fileURL)")
  • Go to the location
  • Delete the store

Deleting the store does the same as when tvOS cleans up the cache to free up space.
Also, note that since the Swiftfin store is stored inside the Cache directory the same issue can also happen on iOS devices with low space. However, it will be less frequent since iOS is less aggressive with cache cleanup.

Now to fix the issue there are multiple solutions:

  • Cache some mandatory models' data outside CoreData, eg. UserDefaults (from what I see it would be ServerModel and UserModel)
  • Store strictly mandatory data alongside the token in the Keychain

Cache outside CoreData
This solution would fix the issue but, from what I understand in the code, this would defeat the purpose of caching to CoreData in the first place. Also, migrating models would be more difficult.

Mandatory data alongside the token in the Keychain
The idea is: if CoreData is empty, we check the Keychain. If the Keychain still contains data we use it to fetch the User/Server remotely. While we are doing this we display a simple loading view. If something fails we disconnect the user/remove the token.
Still from what I understand about Jellyfin / the app, the only missing information would be the server base URL. We could store it alongside the token.
With this solution, the whole app directory can be deleted and it would still recover from scratch using the Keychain.

This is an issue I've already been working on in one of my apps (We called it a PreloadingView -> https://github.com/Infomaniak/ios-kMail/blob/master/Mail/Views/PreloadingView.swift)

I'm still figuring out the whole architecture of the project but if you want me to, I'm willing to try to do some work on this issue using the second solution.

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

No branches or pull requests