Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Use correct containerd error detection.#98

Closed
xenoscopic wants to merge 1 commit intomainfrom
tocttou-cleanup
Closed

Use correct containerd error detection.#98
xenoscopic wants to merge 1 commit intomainfrom
tocttou-cleanup

Conversation

@xenoscopic
Copy link
Contributor

@thaJeztah suggested a more idiomatic approach to error detection. Also we can use the container name rather than ID for inspection, so we don't even need to capture it from the error message.

Signed-off-by: Jacob Howard <jacob.howard@docker.com>
Comment on lines +179 to +180
if errdefs.IsConflict(err) {
if err := waitForContainerToStart(ctx, dockerClient, controllerContainerName); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I just had a thought; given that the "start" endpoint is effectively idempotent for containers that are already started, we could take advantage of that, and after we verified we either created the container, or got a "conflict" (already exists), we can probably just use container start with a retry;

https://github.com/moby/moby/blob/5318877858c9fc94b5cccc3cf1a75d4ec46951b8/daemon/start.go#L76-L93

func (daemon *Daemon) containerStart(ctx context.Context, daemonCfg *configStore, container *container.Container, checkpoint string, checkpointDir string, resetRestartManager bool) (retErr error) {
	ctx, span := otel.Tracer("").Start(ctx, "daemon.containerStart", trace.WithAttributes(append(
		labelsAsOTelAttributes(container.Config.Labels),
		attribute.String("container.ID", container.ID),
		attribute.String("container.Name", container.Name),
	)...))
	defer func() {
		otelutil.RecordStatus(span, retErr)
		span.End()
	}()

	start := time.Now()
	container.Lock()
	defer container.Unlock()

	if resetRestartManager && container.Running { // skip this check if already in restarting step and resetRestartManager==false
		return nil
	}

I haven't verified the approach, but let me write up a quick patch with that idea

Copy link
Member

Choose a reason for hiding this comment

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

@xenoscopic OK; I pushed a PR that's opened against this branch (but feel free to squash it)

⚠️ I have NOT tested it, so probably good if you could give it a spin; let me know what you think!

@xenoscopic
Copy link
Contributor Author

Closing in favor of #107, which incorporates these commits.

@xenoscopic xenoscopic closed this Jun 26, 2025
@xenoscopic xenoscopic deleted the tocttou-cleanup branch July 3, 2025 15:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants