Restructure kill_container method to release semaphore more quickly

This commit is contained in:
Sebastian Serth
2020-03-22 13:22:22 +01:00
parent 123eacb144
commit ff879d85a1

View File

@ -303,23 +303,22 @@ class DockerClient
end end
def kill_container(container) def kill_container(container)
exit_thread_if_alive
Rails.logger.info('killing container ' + container.to_s) Rails.logger.info('killing container ' + container.to_s)
# remove container from pool, then destroy it # remove container from pool, then destroy it
if (DockerContainerPool.config[:active]) if (DockerContainerPool.config[:active])
DockerContainerPool.acquire_semaphore DockerContainerPool.acquire_semaphore
DockerContainerPool.remove_from_all_containers(container, @execution_environment, bypass_semaphore: true) DockerContainerPool.remove_from_all_containers(container, @execution_environment, bypass_semaphore: true)
end
self.class.destroy_container(container)
# if we recylce containers, we start a fresh one
if(DockerContainerPool.config[:active] && RECYCLE_CONTAINERS)
# create new container and add it to @all_containers and @containers. # create new container and add it to @all_containers and @containers.
container = self.class.create_container(@execution_environment) # ToDo: How long does creating a new cotainer take? We're still locking the semaphore.
DockerContainerPool.add_to_all_containers(container, @execution_environment, bypass_semaphore: true) new_container = self.class.create_container(@execution_environment)
DockerContainerPool.add_to_all_containers(new_container, @execution_environment, bypass_semaphore: true)
DockerContainerPool.release_semaphore DockerContainerPool.release_semaphore
end end
exit_thread_if_alive
Thread.new do
self.class.destroy_container(container)
end
end end
def execute_run_command(submission, filename, &block) def execute_run_command(submission, filename, &block)