From ece0ab318be394763eaa345551c3d1f44d2560fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Hauge=20Bj=C3=B8rnskov?= <19725+henrikbjorn@users.noreply.github.com> Date: Wed, 30 Sep 2026 13:31:54 +0200 Subject: [PATCH] End a session quietly when FreeSWITCH resets the socket When FreeSWITCH reset a call's socket (e.g. on uuid_kill), the reader task ended with IO::Stream::ConnectionResetError, and Async logged "Task may have ended with unhandled exception" for every such call. A reset or close from the peer now ends the session the same way as reaching the end of the stream. The listener still gets connection_closed, so pending promises are rejected as before. --- lib/librevox/session.rb | 3 ++ .../functional/librevox/session_reset_test.rb | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/functional/librevox/session_reset_test.rb diff --git a/lib/librevox/session.rb b/lib/librevox/session.rb index 0d40755..14a31e4 100644 --- a/lib/librevox/session.rb +++ b/lib/librevox/session.rb @@ -32,6 +32,9 @@ def start_reader @listener.receive_message(msg) break if @listener.session_complete? end + rescue IOError, Errno::ECONNRESET, Errno::EPIPE + # FreeSWITCH reset or closed the socket (e.g. on uuid_kill): the + # session is over, the same as reaching the end of the stream. ensure @listener.connection_closed end diff --git a/test/functional/librevox/session_reset_test.rb b/test/functional/librevox/session_reset_test.rb new file mode 100644 index 0000000..ce11867 --- /dev/null +++ b/test/functional/librevox/session_reset_test.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require_relative '../../test_helper' +require 'io/stream' + +class TestSessionReset < Minitest::Test + # A connection whose peer resets it mid-stream, as FreeSWITCH does on uuid_kill. + class ResetConnection + def each_message + raise IO::Stream::ConnectionResetError, 'Connection reset by peer!' + end + + def close; end + end + + class Listener + attr_reader :closed + + def run_session; end + + def receive_message(_message); end + + def session_complete? + false + end + + def connection_closed + @closed = true + end + end + + def test_a_reset_connection_ends_the_session_quietly + listener = Listener.new + warnings = capture_io { Sync { Librevox::Session.new(ResetConnection.new, listener).run } }.join + + assert listener.closed, 'the listener still hears that the connection closed' + refute_match(/unhandled exception/, warnings) + end +end