From 790186a1a1eb7249e95d7143c0a25f8ffdcc1129 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Wed, 14 Feb 2024 16:01:44 +0100 Subject: [PATCH] Resolve Tubesock deprecation warnings --- config/initializers/monkey_patches.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/config/initializers/monkey_patches.rb b/config/initializers/monkey_patches.rb index 86878bd1..8df8b639 100644 --- a/config/initializers/monkey_patches.rb +++ b/config/initializers/monkey_patches.rb @@ -28,3 +28,25 @@ module Sorcery end end end + +# Tubesock uses a deprecated method to clear active connections with ActiveRecord. +# Hence, we update the method call to the new method name (including `connection_handler`). +module Tubesock::Hijack + extend ActiveSupport::Concern + + # First, we need to remove the old `included` definition. + # Otherwise, we would get an `ActiveSupport::Concern::MultipleIncludedBlocks` exception. + remove_instance_variable :@_included_block + + included do + def hijack + sock = Tubesock.hijack(request.env) + yield sock + sock.onclose do + ActiveRecord::Base.connection_handler.clear_active_connections! if defined? ActiveRecord + end + sock.listen + render plain: nil, status: -1 + end + end +end