Always close database connection when exiting thread

This commit is contained in:
Sebastian Serth
2020-03-22 15:14:46 +01:00
parent b4c0a14a35
commit 0338564bf2

View File

@ -266,16 +266,15 @@ class DockerClient
as it is impossible to determine whether further input is requested. as it is impossible to determine whether further input is requested.
" "" " ""
@thread = Thread.new do @thread = Thread.new do
#begin
timeout = @execution_environment.permitted_execution_time.to_i # seconds timeout = @execution_environment.permitted_execution_time.to_i # seconds
sleep(timeout) sleep(timeout)
if container.status != :returned if container.status != :returned
Rails.logger.info('Killing container after timeout of ' + timeout.to_s + ' seconds.') Rails.logger.info('Killing container after timeout of ' + timeout.to_s + ' seconds.')
# send timeout to the tubesock socket # send timeout to the tubesock socket
if (@tubesock) if @tubesock
@tubesock.send_data JSON.dump({'cmd' => 'timeout'}) @tubesock.send_data JSON.dump({'cmd' => 'timeout'})
end end
if (@socket) if @socket
@socket.send('#timeout') @socket.send('#timeout')
#sleep one more second to ensure that the message reaches the submissions_controller. #sleep one more second to ensure that the message reaches the submissions_controller.
sleep(1) sleep(1)
@ -283,12 +282,13 @@ class DockerClient
end end
Thread.new do Thread.new do
kill_container(container) kill_container(container)
ensure
ActiveRecord::Base.connection_pool.release_connection
end end
end end
#ensure ensure
# guarantee that the thread is releasing the DB connection after it is done # guarantee that the thread is releasing the DB connection after it is done
# ApplicationRecord.connectionpool.releaseconnection ActiveRecord::Base.connection_pool.release_connection
#end
end end
end end