From c457cd830fd24132e2e376e2ca5e028718b33a17 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 22 Oct 2022 15:57:17 -0500 Subject: [PATCH] workaround for launch bug --- jupyter_client/connect.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/jupyter_client/connect.py b/jupyter_client/connect.py index 0e88c11ef..f9c98bbd1 100644 --- a/jupyter_client/connect.py +++ b/jupyter_client/connect.py @@ -158,6 +158,18 @@ def write_connection_file( cfg["signature_scheme"] = signature_scheme cfg["kernel_name"] = kernel_name + # Prevent over-writing a file that has already been written with the same + # info. This is to prevent a race condition where the process has + # already been launched but has not yet read the connection file. + if os.path.exists(fname): + with open(fname) as f: + try: + data = json.load(f) + if data == cfg: + return fname, cfg + except Exception: + pass + # Only ever write this file as user read/writeable # This would otherwise introduce a vulnerability as a file has secrets # which would let others execute arbitrarily code as you