From 36d657a2146082381fb534dca9644e5c6f5a1d12 Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Sat, 22 Nov 2025 21:57:23 -0500 Subject: [PATCH 1/3] fixed json write operation --- src/radical/utils/json_io.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/radical/utils/json_io.py b/src/radical/utils/json_io.py index d2aec7dea..4ea687bab 100644 --- a/src/radical/utils/json_io.py +++ b/src/radical/utils/json_io.py @@ -70,8 +70,8 @@ def write_json(data, fname): dirname = os.path.dirname(fname) or '.' - _, t_name = tempfile.mkstemp(dir=dirname) - with open(t_name, 'w') as f_out: + fd, t_name = tempfile.mkstemp(dir=dirname) + with os.fdopen(fd, 'w') as f_out: f_out.write('%s\n' % str_data) os.rename(t_name, fname) From c8511f4263aa966b19b81569df1eb39e16c465f0 Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Sun, 23 Nov 2025 23:35:57 -0500 Subject: [PATCH 2/3] fixed json write operation --- src/radical/utils/json_io.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/radical/utils/json_io.py b/src/radical/utils/json_io.py index 4ea687bab..3b783fe73 100644 --- a/src/radical/utils/json_io.py +++ b/src/radical/utils/json_io.py @@ -71,10 +71,17 @@ def write_json(data, fname): dirname = os.path.dirname(fname) or '.' fd, t_name = tempfile.mkstemp(dir=dirname) - with os.fdopen(fd, 'w') as f_out: - f_out.write('%s\n' % str_data) - - os.rename(t_name, fname) + try: + with os.fdopen(fd, 'w') as f_out: + f_out.write('%s\n' % str_data) + os.rename(t_name, fname) + except Exception: + # cleanup the temp file + try: + os.unlink(t_name) + except OSError: + pass + raise # ------------------------------------------------------------------------------ From 43220c82eaeb70d4227faf24f79962b3ac19c859 Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Thu, 15 Jan 2026 16:23:10 -0500 Subject: [PATCH 3/3] fixed issue related to a file descriptor leak Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/radical/utils/json_io.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/radical/utils/json_io.py b/src/radical/utils/json_io.py index 3b783fe73..5fbdbc44b 100644 --- a/src/radical/utils/json_io.py +++ b/src/radical/utils/json_io.py @@ -76,6 +76,11 @@ def write_json(data, fname): f_out.write('%s\n' % str_data) os.rename(t_name, fname) except Exception: + # The fd from mkstemp can be leaked if os.fdopen fails, so close it. + try: + os.close(fd) + except OSError: + pass # cleanup the temp file try: os.unlink(t_name)