Skip to content

finalizer fails to clean up last container if send_file is called - #768

Merged
mizzy merged 1 commit into
mizzy:masterfrom
ichylinux:master
Oct 3, 2026
Merged

mizzy merged 1 commit into
mizzy:masterfrom
ichylinux:master

Conversation

@ichylinux

Copy link
Copy Markdown
Contributor

after running itamae recipes against docker image, sometimes container left not cleaned up.
it happens when we use one of file handling recipes which calls specinfra send_file.

we tested with Ruby-3.4.9 + itamae.gem-1.15.0 + specinfra.gem-2.95.1.

log output like the below shows finalizer failed to stop+remove a container.

/home/myuser/.rbenv/versions/3.4.9/bin/bundle: warning: Exception in finalizer #<Proc:0x00007fce50917208 /home/myuser/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/specinfra-2.95.1/lib/specinfra/backend/docker.rb:37>
/home/myuser/.rbenv/versions/3.4.9/lib/ruby/gems/3.4.0/gems/docker-api-2.4.0/lib/docker/connection.rb:87:in 'Docker::Connection#request': {"message":"No such container: 175a68d23ed93990358cff2cf9ef1c417fb787922a61080cd4819935a4a08416"} (Docker::Error::NotFoundError)

and docker ps -a shows one container remains.

$ docker ps -a
CONTAINER ID   IMAGE          COMMAND                   CREATED         STATUS         PORTS             NAMES
916dc640da9b   592dad67cb8c   ...

the conainer not found and the container left have different container ids.

the problem is that ObjectSpace.define_finalizer(self, self.class.__send__(:finalizer_for, @container)) will hold the container at the time of this line, but later send_file replaces the value of the instance variable @container to the newly created container.

when finalizer tries to clean up the initial container, send_file already took care of it and that leads to No such container.
no one takes care of the container which send_file created.

finalizer should follow the change of @container.

@ichylinux ichylinux changed the title finalizer failes to clean up last container if send_file is called finalizer fails to clean up last container if send_file is called Oct 1, 2026
@ichylinux

Copy link
Copy Markdown
Contributor Author

hi @mizzy

can you review this PR?

@mizzy
mizzy merged commit f83f6e1 into mizzy:master Oct 3, 2026
10 checks passed
@mizzy

mizzy commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Thanks!

@mizzy

mizzy commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Released as v2.95.2.

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.

2 participants