Scheduler Lock Error

Getting this error

bench start
11:00:33 system        | redis_cache.1 started (pid=609555)
11:00:33 system        | redis_queue.1 started (pid=609560)
11:00:33 redis_queue.1 | 609561:C 05 Jun 2024 11:00:33.299 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
11:00:33 system        | socketio.1 started (pid=609566)
11:00:33 system        | watch.1 started (pid=609565)
11:00:33 system        | schedule.1 started (pid=609570)
11:00:33 redis_cache.1 | 609558:C 05 Jun 2024 11:00:33.301 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
11:00:33 redis_cache.1 | 609558:C 05 Jun 2024 11:00:33.302 # Redis version=6.0.16, bits=64, commit=00000000, modified=0, pid=609558, just started
11:00:33 redis_cache.1 | 609558:C 05 Jun 2024 11:00:33.303 # Configuration loaded
11:00:33 redis_cache.1 | 609558:M 05 Jun 2024 11:00:33.303 * Increased maximum number of open files to 10032 (it was originally set to 1024).
11:00:33 system        | web.1 started (pid=609577)
11:00:33 redis_cache.1 | 609558:M 05 Jun 2024 11:00:33.304 * Running mode=standalone, port=13000.
11:00:33 redis_cache.1 | 609558:M 05 Jun 2024 11:00:33.305 # Server initialized
11:00:33 redis_cache.1 | 609558:M 05 Jun 2024 11:00:33.305 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
11:00:33 redis_cache.1 | 609558:M 05 Jun 2024 11:00:33.306 * Ready to accept connections
11:00:33 redis_queue.1 | 609561:C 05 Jun 2024 11:00:33.306 # Redis version=6.0.16, bits=64, commit=00000000, modified=0, pid=609561, just started
11:00:33 redis_queue.1 | 609561:C 05 Jun 2024 11:00:33.306 # Configuration loaded
11:00:33 redis_queue.1 | 609561:M 05 Jun 2024 11:00:33.307 * Increased maximum number of open files to 10032 (it was originally set to 1024).
11:00:33 redis_queue.1 | 609561:M 05 Jun 2024 11:00:33.308 * Running mode=standalone, port=11000.
11:00:33 redis_queue.1 | 609561:M 05 Jun 2024 11:00:33.308 # Server initialized
11:00:33 redis_queue.1 | 609561:M 05 Jun 2024 11:00:33.308 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
11:00:33 redis_queue.1 | 609561:M 05 Jun 2024 11:00:33.309 * Ready to accept connections
11:00:33 system        | worker.1 started (pid=609573)
11:00:33 socketio.1    | Realtime service listening on:  9000
11:00:34 watch.1       | 
11:00:34 watch.1       | yarn run v1.22.19
11:00:34 watch.1       | $ node esbuild --watch --live-reload
11:00:35 web.1         | WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
11:00:35 web.1         |  * Running on all addresses (0.0.0.0)
11:00:35 web.1         |  * Running on http://127.0.0.1:8000
11:00:35 web.1         |  * Running on http://134.209.153.243:8000
11:00:35 web.1         | Press CTRL+C to quit
11:00:35 web.1         |  * Restarting with watchdog (inotify)
11:00:35 web.1         |  * Debugger is active!
11:00:35 web.1         |  * Debugger PIN: 643-584-787
11:00:35 schedule.1    | Failed to log error in db: Filelock: Failed to aquire /home/frappe/frappe-bench/config/scheduler_process.lock
11:00:35 schedule.1    | Traceback (most recent call last):
11:00:35 schedule.1    |   File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/synchronization.py", line 40, in filelock
11:00:35 schedule.1    |     with _StrongFileLock(lock_path, timeout=timeout):
11:00:35 schedule.1    |   File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/filelock/_api.py", line 297, in __enter__
11:00:35 schedule.1    |     self.acquire()
11:00:35 schedule.1    |   File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/filelock/_api.py", line 264, in acquire
11:00:35 schedule.1    |     raise Timeout(lock_filename)  # noqa: TRY301
11:00:35 schedule.1    | filelock._error.Timeout: The file lock '/home/frappe/frappe-bench/config/scheduler_process.lock' could not be acquired.
11:00:35 schedule.1    | 
11:00:35 schedule.1    | The above exception was the direct cause of the following exception:
11:00:35 schedule.1    | 
11:00:36 schedule.1    | Traceback (most recent call last):
11:00:36 schedule.1    |   File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
11:00:36 schedule.1    |     return _run_code(code, main_globals, None,
11:00:36 schedule.1    |   File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
11:00:36 schedule.1    |     exec(code, run_globals)
11:00:36 schedule.1    |   File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 128, in <module>
11:00:36 schedule.1    |     main()
11:00:36 schedule.1    |   File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 34, in main
11:00:36 schedule.1    |     FrappeCommandGroup(commands=commands)(prog_name="bench")
11:00:36 schedule.1    |   File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
11:00:36 schedule.1    |     return self.main(*args, **kwargs)
11:00:36 schedule.1    |   File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1078, in main
11:00:36 schedule.1    |     rv = self.invoke(ctx)
11:00:36 schedule.1    |   File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
11:00:36 schedule.1    |     return _process_result(sub_ctx.command.invoke(sub_ctx))
11:00:36 schedule.1    |   File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
11:00:36 schedule.1    |     return _process_result(sub_ctx.command.invoke(sub_ctx))
11:00:36 schedule.1    |   File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
11:00:36 schedule.1    |     return ctx.invoke(self.callback, **ctx.params)
11:00:36 schedule.1    |   File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 783, in invoke
11:00:36 schedule.1    |     return __callback(*args, **kwargs)
11:00:36 schedule.1    |   File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/scheduler.py", line 179, in start_scheduler
11:00:36 schedule.1    |     start_scheduler()
11:00:36 schedule.1    |   File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/scheduler.py", line 49, in start_scheduler
11:00:36 schedule.1    |     with filelock("scheduler_process", timeout=1, is_global=True):
11:00:36 schedule.1    |   File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
11:00:36 schedule.1    |     return next(self.gen)
11:00:36 schedule.1    |   File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/synchronization.py", line 45, in filelock
11:00:36 schedule.1    |     raise LockTimeoutError(
11:00:36 schedule.1    | frappe.utils.file_lock.LockTimeoutError: Failed to aquire lock: scheduler_process. Lock may be held by another process.<br>You can manually remove the lock if you think it's safe: /home/frappe/frappe-bench/config/scheduler_process.lock
11:00:36 system        | schedule.1 stopped (rc=1)
11:00:36 system        | sending SIGTERM to redis_cache.1 (pid 609555)
11:00:36 system        | sending SIGTERM to redis_queue.1 (pid 609560)
11:00:36 system        | sending SIGTERM to web.1 (pid 609577)
11:00:36 system        | sending SIGTERM to socketio.1 (pid 609566)
11:00:36 system        | sending SIGTERM to watch.1 (pid 609565)
11:00:36 system        | sending SIGTERM to worker.1 (pid 609573)
11:00:36 redis_cache.1 | 609558:signal-handler (1717565436) Received SIGTERM scheduling shutdown...
11:00:36 redis_queue.1 | 609561:signal-handler (1717565436) Received SIGTERM scheduling shutdown...
11:00:36 system        | worker.1 stopped (rc=-15)
11:00:36 system        | socketio.1 stopped (rc=-15)
11:00:36 system        | watch.1 stopped (rc=-15)
11:00:36 redis_cache.1 | 609558:M 05 Jun 2024 11:00:36.314 # User requested shutdown...
11:00:36 redis_cache.1 | 609558:M 05 Jun 2024 11:00:36.314 * Removing the pid file.
11:00:36 redis_cache.1 | 609558:M 05 Jun 2024 11:00:36.314 # Redis is now ready to exit, bye bye...
11:00:36 system        | redis_cache.1 stopped (rc=-15)
11:00:36 redis_queue.1 | 609561:M 05 Jun 2024 11:00:36.327 # User requested shutdown...
11:00:36 redis_queue.1 | 609561:M 05 Jun 2024 11:00:36.327 * Removing the pid file.
11:00:36 redis_queue.1 | 609561:M 05 Jun 2024 11:00:36.328 # Redis is now ready to exit, bye bye...
11:00:36 system        | redis_queue.1 stopped (rc=-15)
11:00:36 system        | web.1 stopped (rc=-15)

It does work by deleting the mentioned file (/home/frappe/frappe-bench/config/scheduler_process.lock), but how can this error be resolved ? and what’s the root cause of this issue ?