Skip to content

Containers in 'creating' state should not be preemptively garbage-collected #1576

Closed

Description

@vito

Today our container collector will find CREATING containers and garbage-collect them by forcing them into CREATED state. This introduces an inconsistency if there were volumes being created for the container, and also results in possibly-unsafe-or-at-least-inelegant destroying of the container while it's being created in Garden.

Here's a sample of an error that can result from this unsafe state transition:

STATEMENT: DELETE FROM containers WHERE id = $1 AND state = $2 
CONTEXT:   SQL statement "UPDATE ONLY "public"."volumes" SET "container_id" = NULL WHERE $1 OPERATOR(pg_catalog.=) "container_id"" 
DETAIL:    Failing row contains (1904179, 0e3b2247-0b32-45d3-583b-b0b2f1c99104, null, null, concourse-windows-worker, null, null, /tmp/build/a1ce2fc4, null, null, null, 16, creating, null, null, null, null, null). 
ERROR:     new row for relation "volumes" violates check constraint "cannot_invalidate_during_initialization" 

This results in un-deleteable rows from the database: the container can't be deleted, because there's a 'creating' volume present for it. The volume will not be garbage-collected, as it's still referencing the container.

Ideally, we wouldn't even look at CREATING containers during garbage-collection. We should be able to rely on the container eventually making it to CREATED. However there may be cases we need to handle, such as failure to create the container in Garden. We'd also have to make sure it's truly eventually-consistent, so we don't end up with any orphaned CREATING containers.

/cc @topherbullock

Activity

  1. jama22 commented on Sep 11, 2017

    @jama22

    We will know this worked if...

    • we have no more containers stuck in the creating state
    • we have no more containers stuck in the destroying state
    • there's nothing leaked on the worker

    Let's first remove today's GCing of CREATING containers, and try a few things that may result in "stuck" CREATING containers:

    • Failure to create a container's volume.
    • Failure to create the container.
    • Restarting the ATC and removing the thing that "owned" the container (pipeline?). Try this for both build containers and resource check containers.

    Once we've reproduced the issue, let's figure out a safe way to remove them, with the following constraints:

    • CREATED should always mean that everything went as expected, and the container is definitely on the worker.
    • DESTROYING should always mean that we've started to remove it via the garbage-collector.
    • If the container is gone from the database, that should always mean that it's gone from the worker.
  2. added 2 commits that reference this issue on Sep 28, 2017
  3. vito commented on Jun 28, 2018

    @vito
    ContributorAuthor

    As of today, we no longer garbage-collect CREATING containers, and the cannot_invalidate_during_initialization constraint has been removed. However we still emit metrics, and I can see that we have quite a few containers stuck in CREATING state.

    I'm going to leave this issue open because we technically have no exit from the state machine when a container is stuck CREATING. I think it'll take some time to catalogue the reasons why these containers didn't make it any further, though, and since it's pretty harmless at the moment I'm willing to leave it be.

  4. stale commented on Aug 8, 2019

    @stale

    Beep boop! This issue has been idle for long enough that it's time to check in and see if it's still important.

    If it is, what is blocking it? Would anyone be interested in submitting a PR or continuing the discussion to help move things forward?

    If no activity is observed within the next week, this issue will be exterminated closed, in accordance with our stale issue process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions