Message ID | 20240229215638.516053-1-yoann.congal@smile.fr |
---|---|
State | Accepted, archived |
Commit | 40d00bf9308e0bf73a00134a99a012a292daa1c5 |
Headers | show |
Series | prserv/serv: Fix a PID file removal race on prserv stop | expand |
On Thu, 2024-02-29 at 22:56 +0100, Yoann Congal wrote: > A race condition has happened where the exiting server removed the PID > file between the existence check and the removal, resulting in a > FileNotFoundError exception. > > The fix is to ignore the FileNotFoundError exception, the existence > check is now redundant so remove it to simplify. > > Fixes [YOCTO #14341] > > Signed-off-by: Yoann Congal <yoann.congal@smile.fr> > --- > lib/prserv/serv.py | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) Thanks, I've meant to do that for a while but good to close the issue and resolve the underlying bug! Cheers, Richard
diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py index 62d3b5a0..5fc8863f 100644 --- a/lib/prserv/serv.py +++ b/lib/prserv/serv.py @@ -262,8 +262,11 @@ def stop_daemon(host, port): os.kill(pid, signal.SIGTERM) time.sleep(0.1) - if os.path.exists(pidfile): + try: os.remove(pidfile) + except FileNotFoundError: + # The PID file might have been removed by the exiting process + pass except OSError as e: err = str(e)
A race condition has happened where the exiting server removed the PID file between the existence check and the removal, resulting in a FileNotFoundError exception. The fix is to ignore the FileNotFoundError exception, the existence check is now redundant so remove it to simplify. Fixes [YOCTO #14341] Signed-off-by: Yoann Congal <yoann.congal@smile.fr> --- lib/prserv/serv.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)