Fixed container-ending on exit.

This commit is contained in:
Alexander Kastius
2016-09-09 17:06:30 +02:00
parent 3fd43fdee2
commit 6ff3d36809
2 changed files with 12 additions and 5 deletions

View File

@ -129,7 +129,7 @@ class SubmissionsController < ApplicationController
socket.on :message do |event|
Rails.logger.info( Time.now.getutc.to_s + ": Docker sending: " + event.data)
handle_message(event.data, tubesock)
handle_message(event.data, tubesock, result[:container])
end
socket.on :close do |event|
@ -171,10 +171,11 @@ class SubmissionsController < ApplicationController
tubesock.close
end
def handle_message(message, tubesock)
def handle_message(message, tubesock, container)
# Handle special commands first
if (/^exit/.match(message))
kill_socket(tubesock)
@docker_client.exit_container(container)
else
# Filter out information about run_command, test_command, user or working directory
run_command = @submission.execution_environment.run_command % command_substitutions(params[:filename])

View File

@ -261,16 +261,21 @@ class DockerClient
end
end
def exit_container(container)
Rails.logger.debug('exiting container ' + container.to_s)
# exit the timeout thread if it is still alive
def exit_thread_if_alive
if(@thread && @thread.alive?)
@thread.exit
end
end
def exit_container(container)
Rails.logger.debug('exiting container ' + container.to_s)
# exit the timeout thread if it is still alive
exit_thread_if_alive
# if we use pooling and recylce the containers, put it back. otherwise, destroy it.
(DockerContainerPool.config[:active] && RECYCLE_CONTAINERS) ? self.class.return_container(container, @execution_environment) : self.class.destroy_container(container)
end
def kill_container(container)
Rails.logger.info('killing container ' + container.to_s)
# remove container from pool, then destroy it
@ -286,6 +291,7 @@ class DockerClient
container = self.class.create_container(@execution_environment)
DockerContainerPool.add_to_all_containers(container, @execution_environment)
end
exit_thread_if_alive
end
def execute_run_command(submission, filename, &block)