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

Stopping Plex Service does not stop all Plex Media Server processes #29

Closed
NS001 opened this issue Dec 18, 2017 · 20 comments
Closed

Stopping Plex Service does not stop all Plex Media Server processes #29

NS001 opened this issue Dec 18, 2017 · 20 comments

Comments

@NS001
Copy link

NS001 commented Dec 18, 2017

Stopping Plex Service via Windows service control manager (e.g. Services MMC snapp-in) does not stop all process started by Plex Service / the Plex Media Server service account used by Plex Service

Step to reproduce:

  1. Using Task Manger, note that no processes are running as the Plex Media Server service account
  2. Install Plex Service and configure a service account in Plex Service
  3. Start the Plex Service Windows service (it starts Plex Media Server)
  4. Using Task Manger, note that several processes are running as the Plex Media Server service account
  5. Right-click the Plex Service notification area icon and choose "Stop Plex"
  6. Using Task Manger, note that now no processes are running as the Plex Media Server service account. Plex Service stopped them all
  7. Right-click the Plex Service notification area icon and choose "Start Plex"
  8. Using Task Manger, note processes running as the Plex Media Server service account again
  9. Using the Windows "Services" MMC snap-in, stop the "Plex Service" Windows service
  10. Using Task Manger, note that several processes are still running as the Plex Media Server service account. The expected outcome is that there are no Plex Media Server service account processes running

Thanks for the great software. Hopefully you can reproduce this but do let me know if you need any more information. Thanks.

@ebjornset
Copy link

Hi, I've experience the same issue, I'm running WIndows Server 2016 Core.

Here is a Powershell session that shows the problem:

C:\Users\PlexService\Documents> [System.Environment]::OSVersion.Version

Major Minor Build Revision


10 0 16299 0

C:\Users\PlexService\Documents> Get-Service Plex*

Status Name DisplayName


Stopped PlexService PlexService
Stopped PlexUpdateService Plex Update Service

C:\Users\PlexService\Documents> Get-Process Plex*
C:\Users\PlexService\Documents>
C:\Users\PlexService\Documents> Start-Service PlexService
C:\Users\PlexService\Documents> Get-Process Plex*

Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName


510      51    10664      15232       0.11   3756   0 Plex DLNA Server
929      64    34608      44564       3.27   3076   0 Plex Media Server
424      24    26088      34664       2.23   1360   0 PlexScriptHost
298      17    25132      32864       1.27   1468   0 PlexScriptHost
352      24    19560      27584       0.25   3708   0 PlexService

C:\Users\PlexService\Documents> Get-Service Plex*

Status Name DisplayName


Running PlexService PlexService
Stopped PlexUpdateService Plex Update Service

C:\Users\PlexService\Documents> Stop-Service PlexService
C:\Users\PlexService\Documents> Get-Service Plex*

Status Name DisplayName


Stopped PlexService PlexService
Stopped PlexUpdateService Plex Update Service

C:\Users\PlexService\Documents> Get-Process Plex*

Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName


437      46    10644      15616       0.20   3756   0 Plex DLNA Server
808      53    33132      45592       3.72   3076   0 Plex Media Server
412      23    25944      34616       2.25   1360   0 PlexScriptHost
312      20    24416      31920       1.39   1468   0 PlexScriptHost

C:\Users\PlexService\Documents> get-content "C:\Users\PlexService\AppData\Local\Plex Service\plexServiceLog.txt"
2/15/2018 11:53:57 AM: Plex executable found at C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Server.exe
2/15/2018 11:53:57 AM: Successfully set the 'FirstRun' registry key to 0
2/15/2018 11:53:57 AM: Attempting to start Plex
2/15/2018 11:53:57 AM: Plex Service Started
2/15/2018 11:53:57 AM: Plex Media Server version is 1.11.0.4666. Can use startup argument.
2/15/2018 11:53:57 AM: Plex Media Server Started.
2/15/2018 11:54:09 AM: Plex Service Stopped

cjmurph added a commit that referenced this issue Feb 16, 2018
@cjmurph
Copy link
Owner

cjmurph commented Feb 16, 2018

Should be resolved in release 1.1.5. Please test and I'll close this issue. Thanks.

@ebjornset
Copy link

@cjmurph I've just upgraded to version 1.1.5 and can confirm that it solved the issue on my machine:-)

Thanks for the quick response, and for this great software!

@cjmurph
Copy link
Owner

cjmurph commented Feb 16, 2018

Great, thanks!

@cjmurph cjmurph closed this as completed Feb 16, 2018
@NS001
Copy link
Author

NS001 commented Feb 19, 2018

Thanks for that. I've just upgraded to 1.1.5 but it doesn't fix it for me (unfortunately). Stopping the Plex Service from the Windows Service Control Manager (e.g. Computer Management's services snap-in) leaves four processes (2 x conhost.exe, 2 x PlexScriptHost.exe). One thought I had is this: my Plex Media Server service account is an ordinary user (not an administrator) with the user rights to log on as a service and file system permissions to access the service account AppData folder. Ordinary users do have the right to kill their own processes, so perhaps this isn't related.

@cjmurph Is there any more information you'd like me to collect? Thanks.

@cjmurph
Copy link
Owner

cjmurph commented Feb 20, 2018

Interesting. It doesn't try and kill conhost, but it should get all the plexscripthost instances, unless they are spawning after. I tested it many times on my PC and it got them all every time. Is conhost a Plex process or a windows process spawned by a Plex process?

@cjmurph
Copy link
Owner

cjmurph commented Feb 20, 2018

Also, I do have the shutdown call continue after 10 seconds if the stop call hasn't come back as complete. Maybe I can blow that out a bit and see if it's just taking longer on your machine. 10 seconds is a long time though when all your'e doing is killing processes

@NS001
Copy link
Author

NS001 commented Feb 20, 2018

conhost.exe is a window process that's a child of PlexScriptHost.exe (must be a supporting function for console-based executables - probably not spawned explicitly by it but attached automatically by Windows). If PlexScriptHost.exe is killed, it exits (so no need to kill it).

Here's the before after / process trees (note that PlexService.exe and "Plex Media Server.exe", the parent processes of the two remaining ones, have gone, leaving them orphaned). Killing PlexScriptHost.exe manually (using Task Manager) is instant, so I don't think there'd be a delay.

How are you finding the processes to kill? Processes matching names running as the same user as the Plex Service (or that configured in the Plex Service Windows service configuration)? I can run some PowerShell to match your logic and see what it says, if you like.

plex service running
plex service stopped

@NS001
Copy link
Author

NS001 commented Feb 20, 2018

Here's a snippet from the log for the shutdown. Registry Export won't be running - it's a task at start up to run Reg.exe to export the Plex Media Server registry keys for backup purposes. So that all finishes within a second or so.

20/02/2018 07:56:42: Killing Plex. 20/02/2018 07:56:43: Killing Registry Export 20/02/2018 07:56:43: Plex Service Stopped 20/02/2018 07:56:43: Plex Media Server has stopped!

@cjmurph
Copy link
Owner

cjmurph commented Feb 21, 2018

That actually looks like a log from 1.1.4. It doesn't wait at all. Can you try uninstalling and reinstalling rather than upgrading?

@NS001
Copy link
Author

NS001 commented May 5, 2018

I finally got round to uninstalling / reinstalling and trying again, and I then finally got round to writing here. Sorry it took so long.

When I uninstalled, I made sure that all config files, etc. where removed before installing again. Attached is a log that me stopping / starting Plex from the Plex Service menu and also restart Plex Service from Windows. But looks the same in the log, I think.

Practically, I noticed that:

  • Stop Plex from the Plex Service menu kills all Plex processes
  • Restarting Plex Service leave some orphaned (PlexScriptHost.exe I think)
  • Subsequently Stop Plex from the Plex Service menu leaves some Plex processes (presumably those from the Plex Service restart that Plex Service doesn't recognise as an affect of the logic used to identify the processes to kill)
    Would some extra logging help with the Plex Service restart case?

Thanks.

plexServiceLog.txt

@cjmurph
Copy link
Owner

cjmurph commented May 6, 2018

Hi,
when you say restarting, I assume you mean from the windows service console. please correct me if you're doing something else.

The service doesn't keep tabs on the supporting processes, other than, when plex stops, it has a list of process names to hunt down and kill. So, there really shouldn't be any "orphaned" processes left behind, unless the shutdown procedure is cut short for some reason. I absolutely cannot replicate what you're showing for a restart case. On the three test machines I have, it behaves exactly as expected, with one caveat... Plex update service will always come back as it is actually a windows service itself and I shouldn't even be attempting to kill it. I'll remove it from the list for the next release.

I would llike to ensure this does in fact work correctly, however I must ask why you would even restart the service? The service itself should always remain running, and plex should be started and stopped from the tray icon (which doesn't start and stop the service, just plex).

Thanks!

@cjmurph
Copy link
Owner

cjmurph commented May 6, 2018

Interestingly, your logs don't show plex attempting to kill any of the supporting processes, It only kills plex and what looks like an auxilliary application called "Registry Export". Are you on the latest version?

@NS001
Copy link
Author

NS001 commented May 6, 2018

Hi. Taking your questions one-by-one...

"from the windows service console" - Yes. For example, services.msc

"unless the shutdown procedure is cut short for some reason" - I think Windows waits for at least 30 seconds before timing out a Windows service shutdown / restart (timing out to the application doing the restart like services.mcs, but probably carries on the shutdown or shutdown part of the restart anyway in the background). In this case, the Plex Service restarts quite quickly, suggesting it quits quickly too (either gracefully or otherwise).

"Plex update service will always come back" - I've got that service disabled (and a scheduled task to keep it that way)

"why you would even restart the service?" - The use case for I have is a scheduled task that runs daily to backup (using Robocopy mirror) data to a different computer. For certain sets of data that it copies, it needs to shut down the service that uses the data, otherwise files are in use and can't be copied (or potentially inconsistent). The same orphaned processes apply with Plex Service is shutdown from services.msc, which is what the backup Windows PowerShell script does. I could manually kill the orphaned processes in the script (after issuing a Plex Service shutdown), but the scheduled task that runs the backup script runs as an ordinary user (for security via least privilege) but with permission previously granted to control the Plex Service (done via SC.exe).

"auxilliary application called "Registry Export"" - That's a command I run to export the Plex registry settings using "Reg.exe Export" to allow for recovery of the Plex database from backup. I've verified that Reg.exe runs, does it's job then quits at Plex startup, so there's nothing to kill.

"Are you on the latest version?" - This is with 1.1.5 (previously it was on the same version but it was an upgrade and you said the logs looked like it hadn't upgraded properly: hence the clean installation).

Thanks.

@cjmurph
Copy link
Owner

cjmurph commented May 7, 2018

Great info, thank you :)

ok, my primary concern is that the logs don't show any attempt at all to kill those processes.

When the service is called to stop, it issues the stop command and awaits the state to change to stopped, which only happens after cleaning up all the extra processes and auxiliary applications. It doesn't take very long and the wait will timeout after 10 seconds (if it takes that long there is a problem anyway).

I'll add some more in depth logging to the service logs around this procedure and get you to try with that. I'll hopefully get to that tonight or tomorrow.

cjmurph added a commit that referenced this issue May 7, 2018
@cjmurph
Copy link
Owner

cjmurph commented May 7, 2018

I've added more verbose logging in release 1.1.7.

you should get a log file that looks like the following when stopping plex:

7/05/2018 9:12:35 PM: Killing Plex.
7/05/2018 9:12:35 PM: Plex Media Server has stopped!
7/05/2018 9:12:35 PM: Killing supporting processes.
7/05/2018 9:12:35 PM: Looking for Plex DLNA Server
7/05/2018 9:12:35 PM: 0 instances of Plex DLNA Server found
7/05/2018 9:12:35 PM: Looking for PlexScriptHost
7/05/2018 9:12:35 PM: 2 instances of PlexScriptHost found
7/05/2018 9:12:35 PM: Stopping PlexScriptHost with PID 10268
7/05/2018 9:12:35 PM: PlexScriptHost with PID stopped
7/05/2018 9:12:35 PM: Stopping PlexScriptHost with PID 7920
7/05/2018 9:12:35 PM: PlexScriptHost with PID stopped
7/05/2018 9:12:35 PM: Looking for PlexTranscoder
7/05/2018 9:12:35 PM: 0 instances of PlexTranscoder found
7/05/2018 9:12:35 PM: Looking for PlexNewTranscoder
7/05/2018 9:12:35 PM: 0 instances of PlexNewTranscoder found
7/05/2018 9:12:35 PM: Looking for Plex Media Scanner
7/05/2018 9:12:35 PM: 0 instances of Plex Media Scanner found
7/05/2018 9:12:35 PM: Looking for PlexRelay
7/05/2018 9:12:35 PM: 0 instances of PlexRelay found
7/05/2018 9:12:35 PM: Looking for EasyAudioEncoder
7/05/2018 9:12:35 PM: 0 instances of EasyAudioEncoder found
7/05/2018 9:12:35 PM: Looking for Plex Tuner Service
7/05/2018 9:12:35 PM: 0 instances of Plex Tuner Service found

@cjmurph cjmurph reopened this May 7, 2018
@NS001
Copy link
Author

NS001 commented May 10, 2018

Hi.

Thanks for that - upgraded.

Before test: Stop Plex via Plex Service. Stop Plex Service. Check that no processes are running as the Plex service account user

19:43 - Start Plex Service. Processing running after: 3 x connhost.exe, 1 x Plex Media Server.exe, 2 x PlexScriptHost.exe, 1 x Plex Tuner Service.exe
19:45 - Stop Plex via Plex Service. Result: OK. No Plex processes running
19:46 - Start Plex via Plex Service
19:47 - Stop Plex Service from services.msc. Result: OK. No Plex processes running
19:48 - Start Plex Service
19:49 - Restart Plex Service from services.msc. Processing running after: 3 x connhost.exe, 1 x Plex Media Server.exe, 2 x PlexScriptHost.exe, 1 x Plex Tuner Service.exe
19:50 - Restart Plex Service from services.msc. Processing running after: 3 x connhost.exe, 1 x Plex Media Server.exe, 2 x PlexScriptHost.exe, 1 x Plex Tuner Service.exe
19:52: Stop Plex Service from services.msc. Result: Result: 2 x connhost.exe, 2 x PlexScriptHost.exe left running

Weird. If you look at the log, the last Plex Service stop at 19:52 didn't have the log entries for the process clean up ("Plex Media Server has stopped!" to "Plex Service Stopped"). This is the test where the PMS processes were left running. The same action at 19:47 does have the actions and the processes were killed

plexServiceLog.txt

@cjmurph
Copy link
Owner

cjmurph commented May 10, 2018

It's definitely terminating early. I wonder if it's actually crashing during stop. Can you have a look at the windows event viewer at those times?

I'm away for work at the moment, but I'll see if I can get a VM up and running to test.

@NS001
Copy link
Author

NS001 commented May 10, 2018

Nothing in the Application or System logs to indicate a user-mode crash. No rush to do anything at all: as and when you can.

The only thing I can see is event ID 10016 in the System log a couple of minutes after PMS starts:

The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID
{D63B10C5-BB46-4990-A94F-E40B9D520160}
and APPID
{9CA88EE3-ACB7-47C8-AFC4-AB702511C276}
to the user COMPUTERNAMEREMOVED\SERVICEACCOUNTREMOVED SID (SIDREMOVED) from address LocalHost (Using LRPC) running in the application container Unavailable SID (Unavailable). This security permission can be modified using the Component Services administrative tool.

Both CLSIDs appears to be "C:\Windows\System32\RuntimeBroker.exe"

@cjmurph
Copy link
Owner

cjmurph commented May 13, 2023

it's been 5 years, I don't think this is still a thing.

@cjmurph cjmurph closed this as completed May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants