How to Schedule a regular Restart of a MID Server, to clear recurring Stuck Threads, Memory leaks, Buffers or HandlesIssue It is possible that jobs running in MID Servers get stuck, and then block one of the worker threads, eventually leading to a MID Server with no threads left available to run anything. This can happen due to poor design of custom JavascriptProbe jobs, or there have been some product defects that also leave stuck threads behind after the job has finished. Memory and Handle leaks can also be caused by known problems, eventually making the MID Server unusable, or appear Down even though the service is still running. A MID Sever restart clears stuck threads, and leaked memory and handles. Until your causes of stuck threads are fixed, one possible workaround is to have a scheduled script run periodically to tell the MID Server(s) to restart themselves.ResolutionOpen a list of all MID Servers: In the navigation MID Server -> Servers. (ecc_agent table)Filter the list down to only the MID Servers(s) you need to be restarting. e.g. Name Contains 'Disco'.Add an extra condition for Status IS Up, so that we only restart MID Servers that are running.Right click the blue filter line and 'Copy query'. This will give you the Encoded Query String for this list filter that we will use in the script. e.g. "nameLIKEdisco^status=Up"Open a new Scheduled Script record (sysauto_script): System Definition -> Scheduled Jobs, click New, click Automatically run a script of your choosing.Fill in Name: (custom) Restart MID Servers to clear stuck threadsFill in the schedule fields. e.g. Run: Weekly, Day: Sunday, Time: 07:00:00. Pick a time when no jobs are likely to be running in your MID Servers.Paste the following script into the Run this script field: // scheduled script to regularly restart MID Servers to clear out stuck threads (KB0692080) var midGr = new GlideRecord('ecc_agent'); midGr.addEncodedQuery('<paste query string here>'); // This query string limits which MID Servers are restarted. midGr.query(); while(midGr.next()) { var agent_name = midGr.name.replace(/'/g, "\\'"); var midmanage = new MIDServerManage(); midmanage.restartService(agent_name); // This line writes the restart ecc_queue output to the mid server. gs.info('(custom) Restart MID Servers to clear stuck threads job: Restarting MID Server: ' + agent_name); } Paste your query string copied earlier into the addEncodedQuery function highlighted above. The line will then look like e.g. midGr.addEncodedQuery('nameLIKEdisco^status=Up'); // This query string limits which MID Servers are restarted. Submit. The script will now run on the next scheduled time.To test this script, or run it on demand, use the Execute Now button. Related LinksKB0832784 / PRB1414364 After upgrading to Orlando Patch 5, SNMP Discovery causes a File Handler leak, leaving MID Servers unstable or Down