`create_sibling_ria` does not release `IO` handler resources properly
mih opened this issue · comments
Michael Hanke commented
Here is the word-diff of what needs to change (i.e., wrapping the io
object into a closing
context manager).
Without this change, a remote shell (with SSHRemoteIO
) is not properly closed until process/command exit.
diff --git a/datalad/distributed/create_sibling_ria.py b/datalad/distributed/create_sibling_ria.py
index 15ccd2df6..b43de0712 100644
--- a/datalad/distributed/create_sibling_ria.py
+++ b/datalad/distributed/create_sibling_ria.py
@@ -403,29 +403,29 @@ class CreateSiblingRia(Interface):
# command abstractions
# - more generally consider store creation a dedicated command or
# option
[-io = SSHRemoteIO(ssh_host)-]{+from contextlib import closing+}
{+ with closing(SSHRemoteIO(ssh_host)+} if ssh_host else [-LocalIO()-]{+LocalIO()) as io:+}
try:
# determine the existence of a store by trying to read its layout.
# Because this raises a FileNotFound error if non-existent, we need
# to catch it
io.read_file(local_base_path / 'ria-layout-version')
except (FileNotFoundError, RIARemoteError, RemoteCommandFailedError) as e:
if not new_store_ok:
# we're instructed to only act in case of an existing RIA store
res = get_status_dict(
status='error',
message="No store found at '{}'. Forgot "
"--new-store-ok ?".format(local_base_path),
**res_kwargs)
yield res
return
log_progress(
lgr.info, 'create-sibling-ria',
'Creating a new RIA store at %s', local_base_path,
)
create_store(io, local_base_path, '1')
yield from _create_sibling_ria(
ds,