Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/librevox/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions test/functional/librevox/session_reset_test.rb
Original file line number Diff line number Diff line change
@@ -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