Skip to content

container: delete the container on poststart hooks failures#2051

Open
giuseppe wants to merge 1 commit intocontainers:mainfrom
giuseppe:delete-container-poststart-failure
Open

container: delete the container on poststart hooks failures#2051
giuseppe wants to merge 1 commit intocontainers:mainfrom
giuseppe:delete-container-poststart-failure

Conversation

@giuseppe
Copy link
Member

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the container lifecycle management by introducing a critical cleanup mechanism. Previously, a container might remain in an inconsistent state if its poststart hooks failed. The changes ensure that such containers are automatically deleted, improving system hygiene and preventing resource leakage. This behavior is now also covered by a dedicated test.

Highlights

  • Container Lifecycle Management: Implemented logic to automatically delete a container if any of its poststart hooks fail during the container's startup process. This ensures proper cleanup and prevents orphaned containers.
  • Test Coverage: Added a new test case, test_poststart_fail_deletes_container, to validate that containers are correctly deleted when poststart hooks return a non-zero exit code.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/libcrun/container.c
    • Modified libcrun_container_start to call container_delete_internal if do_hooks for poststart returns an error.
  • tests/test_hooks.py
    • Added test_poststart_fail_deletes_container to verify container deletion on poststart hook failure.
    • Registered the new test in the all_tests dictionary.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly implements the deletion of a container when a post-start hook fails. The accompanying test in tests/test_hooks.py effectively validates this new behavior. I have one suggestion to enhance error logging in the C code.

Comment on lines +3414 to +3419
{
libcrun_error_t tmp_err = NULL;
container_delete_internal (context, def, id, true, true, &tmp_err);
crun_error_release (&tmp_err);
return ret;
}

Choose a reason for hiding this comment

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

medium

The current implementation silently ignores potential errors from container_delete_internal. While the primary error from the hook failure is correctly propagated, it would be more robust to log a warning if the container deletion fails. This would provide better visibility for debugging cleanup issues without altering the main error handling flow.

        {
          libcrun_error_t tmp_err_storage = NULL;
          libcrun_error_t *tmp_err = &tmp_err_storage;
          if (container_delete_internal (context, def, id, true, true, tmp_err) < 0)
            crun_error_write_warning_and_release (context->output_handler_arg, &tmp_err);
          return ret;
        }

Copy link
Contributor

@jnovy jnovy left a comment

Choose a reason for hiding this comment

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

LGTM, just minor things to fix.


try:
run_crun_command(["start", cid])
logger.info("start succeeded but poststart hook should have failed")
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe logger.error would be more appropriate here?


try:
run_crun_command(["state", cid])
logger.info("container still exists after poststart hook failure")
Copy link
Contributor

Choose a reason for hiding this comment

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

Also here.

return 0

except Exception as e:
logger.info("test failed: %s", e)
Copy link
Contributor

Choose a reason for hiding this comment

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

and here?

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe force-pushed the delete-container-poststart-failure branch from 6214f67 to c4f3a89 Compare March 16, 2026 17:49
@giuseppe
Copy link
Member Author

@jnovy fair! Fixed now

@kolyshkin
Copy link
Collaborator

Needs a rebase (after merging #2045)

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.

3 participants