From 2753e4ef5b294fe5a2347b53c3c6fa6228a30d4f Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 11 Nov 2022 22:50:27 +0100 Subject: [PATCH] Always catch StandardError in Threads and release connection --- app/helpers/action_cable_helper.rb | 4 ++++ app/models/submission.rb | 2 ++ lib/prometheus/controller.rb | 2 ++ lib/runner/event_loop.rb | 2 ++ 4 files changed, 10 insertions(+) diff --git a/app/helpers/action_cable_helper.rb b/app/helpers/action_cable_helper.rb index 13027292..60fb84db 100644 --- a/app/helpers/action_cable_helper.rb +++ b/app/helpers/action_cable_helper.rb @@ -13,6 +13,8 @@ module ActionCableHelper locals: {request_for_comment: self}) ) end + rescue StandardError => e + Sentry.capture_exception(e) ensure ActiveRecord::Base.connection_pool.release_connection end @@ -33,6 +35,8 @@ module ActionCableHelper working_time_data: exercise.get_working_times_for_study_group(study_group_id, user) ) end + rescue StandardError => e + Sentry.capture_exception(e) ensure ActiveRecord::Base.connection_pool.release_connection end diff --git a/app/models/submission.rb b/app/models/submission.rb index 41b593d6..ae80c10d 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -312,6 +312,8 @@ class Submission < ApplicationRecord rfc.full_score_reached = true rfc.save end + rescue StandardError => e + Sentry.capture_exception(e) ensure ActiveRecord::Base.connection_pool.release_connection end diff --git a/lib/prometheus/controller.rb b/lib/prometheus/controller.rb index 84fc5192..ba6b0b53 100644 --- a/lib/prometheus/controller.rb +++ b/lib/prometheus/controller.rb @@ -19,6 +19,8 @@ module Prometheus initialize_rfc_metrics rescue StandardError => e Sentry.capture_exception(e) + ensure + ActiveRecord::Base.connection_pool.release_connection end end end diff --git a/lib/runner/event_loop.rb b/lib/runner/event_loop.rb index 037f08d0..28ccbae0 100644 --- a/lib/runner/event_loop.rb +++ b/lib/runner/event_loop.rb @@ -32,6 +32,8 @@ class Runner::EventLoop queue = Queue.new Thread.new do EventMachine.run { queue.push nil } + rescue StandardError => e + Sentry.capture_exception(e) ensure ActiveRecord::Base.connection_pool.release_connection end