Scheduler is overloaded or stuck by Async jobs that are running long while processing sleep functionDescriptionThe purpose of the KB is to know how nonproper use of sleep function caused the Async job to run long.The jobs were stuck and causing scheduler overload This KB helps to know the issue with the sleep function of the script that caused the scheduler overload issueRelease or EnvironmentALL RELEASESCauseThe schedulers were overloaded due to the jobs "ASYNC:Copy attachment from RITM".The jobs were stuck at processing the sleep function that is used in the script.The jobs were running long and not completing and they held the DB connections for long and causing issues.ResolutionThe jobs were running long and when analyzed they seem to be stuck.The stack trace of the jobs was showing as below main,glide.scheduler.worker.1,4 java.lang.Thread.sleep(Native Method) com.glide.script.GlideSystem.js_sleep(GlideSystem.java:1157) sun.reflect.GeneratedMethodAccessor1967.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.mozilla.javascript.MemberBox.invoke(MemberBox.java:138) org.mozilla.javascript.FunctionObject.doInvoke(FunctionObject.java:670) org.mozilla.javascript.FunctionObject.call(FunctionObject.java:614) org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2609) org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32) org.mozilla.javascript.gen.sys_script_e8574f05dbbb0c5026f6553c68961916_script_667419._c_executeRule_1(sys_script.e8574f05dbbb0c5026f6553c68961916.script:13) org.mozilla.javascript.gen.sys_script_e8574f05dbbb0c5026f6553c68961916_script_667419.call(sys_script.e8574f05dbbb0c5026f6553c68961916.script) org.mozilla.javascript.ScriptRuntime.doCall2(ScriptRuntime.java:2678) org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2617) org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:42) org.mozilla.javascript.gen.sys_script_e8574f05dbbb0c5026f6553c68961916_script_667419._c_script_0(sys_script.e8574f05dbbb0c5026f6553c68961916.script:1) org.mozilla.javascript.gen.sys_script_e8574f05dbbb0c5026f6553c68961916_script_667419.call(sys_script.e8574f05dbbb0c5026f6553c68961916.script) org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:563) org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3459) org.mozilla.javascript.gen.sys_script_e8574f05dbbb0c5026f6553c68961916_script_667419.call(sys_script.e8574f05dbbb0c5026f6553c68961916.script) org.mozilla.javascript.gen.sys_script_e8574f05dbbb0c5026f6553c68961916_script_667419.exec(sys_script.e8574f05dbbb0c5026f6553c68961916.script) com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:279) com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:118) com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:82) com.glide.script.Evaluator.evaluatePossiblePrefixedString(Evaluator.java:210) com.glide.job.RunScriptJob.evaluateScript(RunScriptJob.java:173) com.glide.job.RunScriptJob.runScript(RunScriptJob.java:128) com.glide.job.RunScriptJob.execute(RunScriptJob.java:91) com.glide.schedule.JobExecutor.lambda$executeJob$0(JobExecutor.java:113) com.glide.schedule.JobExecutor$$Lambda$271/13461187.call(Unknown Source) com.glide.schedule.JobExecutor.executeJob(JobExecutor.java:116) com.glide.schedule.JobExecutor.execute(JobExecutor.java:100) com.glide.schedule_v2.SchedulerWorkerThread.executeJob(SchedulerWorkerThread.java:300) com.glide.schedule_v2.SchedulerWorkerThread.lambda$process$0(SchedulerWorkerThread.java:188) com.glide.schedule_v2.SchedulerWorkerThread$$Lambda$252/8714644.run(Unknown Source) com.glide.worker.TransactionalWorkerThread.executeInTransaction(TransactionalWorkerThread.java:35) com.glide.schedule_v2.SchedulerWorkerThread.process(SchedulerWorkerThread.java:188) com.glide.schedule_v2.SchedulerWorkerThread.run(SchedulerWorkerThread.java:102) Based on above stack trace we checked the script mentioned above "sys_script.e8574f05dbbb0c5026f6553c68961916.script:13)" The code snippet line 13 is the sleep function that is been running and stuck 3: while(!found){ 4: var grAttachment = new GlideRecord("sys_attachment"); 5: grAttachment.addQuery("table_sys_id", current.getValue("request_item")); 6: grAttachment.query(); 7: if(grAttachment.next()) 8: { 9: GlideSysAttachment.copy("sc_req_item", current.getValue("request_item"), "sc_task", current.getValue("sys_id")); 10: found = true; 11: } 12: else 13: >>> gs.sleep(1000); 14: } We suggested user comment out from code line 12 to code line 14 of the script of the business rule mentioned belowhttps://<Instance-name>/sys_script.do?sys_id=e8574f05dbbb0c5026f6553c68961916 to avoid the issue from reoccurring