Skip to content

Move poststart hook from runc create to runc start#5186

Open
kolyshkin wants to merge 3 commits intoopencontainers:mainfrom
kolyshkin:poststart
Open

Move poststart hook from runc create to runc start#5186
kolyshkin wants to merge 3 commits intoopencontainers:mainfrom
kolyshkin:poststart

Conversation

@kolyshkin
Copy link
Contributor

The runtime-spec 1 currently says:

  1. Runtime's start command is invoked with the unique identifier of
    the container.
  2. The startContainer hooks MUST be invoked by the runtime. If any
    startContainer hook fails, the runtime MUST generate an error, stop
    the container, and continue the lifecycle at step 12.
  3. The runtime MUST run the user-specified program, as specified by
    process.
  4. The poststart hooks MUST be invoked by the runtime. If any
    poststart hook fails, the runtime MUST generate an error, stop the
    container, and continue the lifecycle at step 12.
    ...
  5. Runtime's delete command is invoked with the unique identifier of
    the container.
  6. The container MUST be destroyed by undoing the steps performed
    during create phase (step 2).
  7. The poststop hooks MUST be invoked by the runtime. If any poststop
    hook fails, the runtime MUST log a warning, but the remaining hooks
    and lifecycle continue as if the hook had succeeded.

Currently, we do 9 before 8 (heck, even before 6), which is clearly
against the spec and results in issues like the one described in 2.

Let's move running poststart hook to after the user-specified process
has started.

NOTE this patch only fixes the order and does not implement removing
the container when the poststart hook failed (as this part of the spec
is controversial -- destroy et al and should probably be, and currently
are, part of "runc delete").

Fixes: #5182
Fixes: #4347
Closes: #4348

Rename c.signal to c.signalInit, and add c.signal which is a lock-less
form of c.Signal.

To be used by the next patch.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
No functional change. To be used by the next patch.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
Copy link
Contributor Author

@ningmingxiao @eriksjolund PTAL

@kolyshkin kolyshkin requested review from cyphar, lifubang and rata March 19, 2026 23:08
@kolyshkin kolyshkin added this to the 1.6.0 milestone Mar 19, 2026
The runtime-spec [1] currently says:

> 6. Runtime's start command is invoked with the unique identifier of
>    the container.
> 7. The startContainer hooks MUST be invoked by the runtime. If any
>    startContainer hook fails, the runtime MUST generate an error, stop
>    the container, and continue the lifecycle at step 12.
> 8. The runtime MUST run the user-specified program, as specified by
>    process.
> 9. The poststart hooks MUST be invoked by the runtime. If any
>    poststart hook fails, the runtime MUST generate an error, stop the
>    container, and continue the lifecycle at step 12.
> ...
> 11. Runtime's delete command is invoked with the unique identifier of
>     the container.
> 12. The container MUST be destroyed by undoing the steps performed
>     during create phase (step 2).
> 13. The poststop hooks MUST be invoked by the runtime. If any poststop
>     hook fails, the runtime MUST log a warning, but the remaining hooks
>     and lifecycle continue as if the hook had succeeded.

Currently, we do 9 before 8 (heck, even before 6), which is clearly
against the spec and results in issues like the one described in [2].

Let's move running poststart hook to after the user-specified process
has started.

NOTE this patch only fixes the order and does not implement removing
the container when the poststart hook failed (as this part of the spec
is controversial -- destroy et al and should probably be, and currently
are, part of "runc delete").

[1]: https://github.com/opencontainers/runtime-spec/blob/main/runtime.md#lifecycle
[2]: opencontainers#5182

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@rata
Copy link
Member

rata commented Mar 20, 2026

We will have to revert this if it breaks anyone. But I don't think hooks are so used (they were mostly unexported to upper layers), so hopefully we can do this and no one notices?

@cyphar
Copy link
Member

cyphar commented Mar 20, 2026

I thought we decided to just keep the broken poststart hook as is and push people to use the new createRuntime and friends?

EDIT: I think the issue is that opencontainers/runtime-spec#1169 missed a few changes when changing the explanation of prestart to match what runc does in practice.

@cyphar
Copy link
Member

cyphar commented Mar 20, 2026

I suspect the issue is we just need to update the lifecycle doc in the spec, since the description of prestart says:

The prestart hooks MUST be called as part of the create operation after the runtime environment has been created (according to the configuration in config.json) but before the pivot_root or any equivalent operation has been executed.

@kolyshkin
Copy link
Contributor Author

@cyphar this one is about poststart only. Only prestart is deprecated in the spec (in favor of createContainer and friends).

Currently runc implements poststart hook as part of runc create, while both crun and youki implement it as part of start (i.e. per spec).

I feel we need to fix the discrepancy in one way or another.

@eriksjolund
Copy link
Contributor

@ningmingxiao @eriksjolund PTAL

@kolyshkin I built runc from your branch poststart (git commit 2d88d2e).
Then I tried the reproducer in #5182 .
The file /tmp/poststop-created was created.
In other words, it seems this PR fixes #5182 .

@rata
Copy link
Member

rata commented Mar 23, 2026

@kad this is the PR we were talking yesterday, can you please take a look?

I'd like to the @kad input before we merge, hooks are very much used by GPUs.

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.

poststop hook is not run if poststart hook fails runc's poststart behaviour doesn't match the runtime-spec

4 participants