Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crane / zot launcher: kill registry serve process on shell exit #421

Conversation

malt3
Copy link
Contributor

@malt3 malt3 commented Nov 20, 2023

Fixes #419

Copy link
Collaborator

@thesayyn thesayyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the cleanup procedure doesn't need to leak into call site rules. the launcher script can easily keep a global state and expose a cleanup function that kills the process.

@malt3
Copy link
Contributor Author

malt3 commented Nov 21, 2023

[...] the launcher script can easily keep a global state and expose a cleanup function that kills the process
This is not correct. The start_registry function is invoked in a subshell like this:

readonly REGISTRY=$(start_registry "${STORAGE_DIR}" "${STDERR}" "${REGISTRY_PIDFILE}")

The subshell (and any global state that may be preserved inside) does not survive the subshell invocation.

Or to be more precise:

function start_registry() {
    # [...]
    "${REGISTRY_BIN}" >> $output 2>&1 &
    readonly REGISTRY_PID=$!
    # [...]
     return 0
}

function stop_registry() {
    if [[ -z "${REGISTRY_PID+x}" ]]; then
        echo "Registry not started"
        return 0
    fi
    echo "Stopping registry process ${REGISTRY_PID}"
    kill -9 "${REGISTRY_PID}" || true
    return 0
}

# if I do this, the variable will survive but we cannot easily capture the registry address without writing to a file:
start_registry # [...] args
stop_registry

# if I do this, the variable is only part of the subshell
readonly REGISTRY=$(start_registry # [...] args)
stop_registry

Proposed solutions

  • What do you think about passing a PIDFILE to start_registry and passing the same PIDFILE to stop_registry? Would look a bit cleaner and works with subshells.
  • alternatively, we could have three functions:
    • start_registry (called in same shell as function)
    • stop_registry (called in same shell as function)
    • get_registry (called after start_registry as subshell)

@malt3 malt3 force-pushed the fix/start_registry/kill_registry_process_on_exit branch 2 times, most recently from aba9214 to a31ee09 Compare November 21, 2023 09:34
@thesayyn
Copy link
Collaborator

Ah true, we can write the pid into storage_dir/proc.pid or call pkill -P $$ kill all subprocesses. I'd rather keep the diff minimal.

@malt3 malt3 force-pushed the fix/start_registry/kill_registry_process_on_exit branch from a31ee09 to 55375d5 Compare November 23, 2023 18:15
@malt3
Copy link
Contributor Author

malt3 commented Nov 23, 2023

I think pkill should not be used since it is not part of POSIX and not even in coreutils or util-linux.
I used the fixed path inside the storage dir, as suggested.

Copy link
Collaborator

@thesayyn thesayyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff is still big and there seems to be some formatting changes. Can you revert those?

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@malt3 malt3 force-pushed the fix/start_registry/kill_registry_process_on_exit branch from 55375d5 to df9fdd8 Compare November 27, 2023 08:55
@malt3 malt3 requested a review from thesayyn November 27, 2023 08:56
@thesayyn
Copy link
Collaborator

Sorry @malt3 going to look into this soon.

@thesayyn thesayyn merged commit 57c7b75 into bazel-contrib:main Dec 13, 2023
@malt3 malt3 deleted the fix/start_registry/kill_registry_process_on_exit branch December 13, 2023 21:23
malt3 added a commit to edgelesssys/constellation that referenced this pull request Dec 18, 2023
rules_oci spawns local container registry processes and in the past,
those would not be cleaned up explicitly, leading to an accumulation
of processes when using remote execution with buildbarn.
This pre-release contains a fix: bazel-contrib/rules_oci#421
Additionally, windows support for rules_oci was removed in this fork,
since it is currently broken.
malt3 added a commit to edgelesssys/constellation that referenced this pull request Dec 19, 2023
…2729)

rules_oci spawns local container registry processes and in the past,
those would not be cleaned up explicitly, leading to an accumulation
of processes when using remote execution with buildbarn.
This pre-release contains a fix: bazel-contrib/rules_oci#421
Additionally, windows support for rules_oci was removed in this fork,
since it is currently broken.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crane registry serve daemons are not cleaned up
2 participants