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