From b6b382c4d2bffb38d03d950a9c76cc0158f2866d Mon Sep 17 00:00:00 2001 From: Spencer McIntyre Date: Tue, 13 Feb 2024 16:28:45 -0500 Subject: [PATCH] Catch exception when updating non-existing session --- lib/msf/core/session.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/msf/core/session.rb b/lib/msf/core/session.rb index 55690d8429ac..d28eb65c5f8c 100644 --- a/lib/msf/core/session.rb +++ b/lib/msf/core/session.rb @@ -227,10 +227,11 @@ def via_payload # def cleanup if db_record and framework.db.active - ::ApplicationRecord.connection_pool.with_connection { + ::ApplicationRecord.connection_pool.with_connection do framework.db.update_session(id: db_record.id, closed_at: Time.now.utc, close_reason: db_record.close_reason) - db_record = nil - } + rescue ActiveRecord::RecordNotFound + nil # this will fail if the workspace was deleted before the session was closed, see #18561 + end end end