From 51428814e2f6af85d70280b49d8a46530b941ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Hauge=20Bj=C3=B8rnskov?= <19725+henrikbjorn@users.noreply.github.com> Date: Mon, 16 Mar 2026 09:29:12 +0100 Subject: [PATCH] Remove sleep from listeners, add Async task scoping to Server#run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sleep in run_session was unnecessary — the read_loop in Client/Server keeps the connection alive until FreeSWITCH closes it. Server#run now wraps in Async do |task| with task.children.each(&:wait) to properly drain in-flight connections on shutdown, matching the async-http pattern. --- lib/librevox/listener/inbound.rb | 1 - lib/librevox/listener/outbound.rb | 1 - lib/librevox/server.rb | 5 ++++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/librevox/listener/inbound.rb b/lib/librevox/listener/inbound.rb index d94b2ab..9717f2e 100644 --- a/lib/librevox/listener/inbound.rb +++ b/lib/librevox/listener/inbound.rb @@ -45,7 +45,6 @@ def run_session end connection_completed - sleep # keep session alive for event hooks and child tasks end def connection_completed diff --git a/lib/librevox/listener/outbound.rb b/lib/librevox/listener/outbound.rb index c4e13a1..8f585fb 100644 --- a/lib/librevox/listener/outbound.rb +++ b/lib/librevox/listener/outbound.rb @@ -50,7 +50,6 @@ def run_session send_message "myevents" send_message "linger" session_initiated - sleep # keep session alive for event hooks and child tasks end def handle_response diff --git a/lib/librevox/server.rb b/lib/librevox/server.rb index 6dfd31a..3d24161 100644 --- a/lib/librevox/server.rb +++ b/lib/librevox/server.rb @@ -27,7 +27,10 @@ def accept(socket, _address) end def run - @endpoint.accept(&method(:accept)) + Async do |task| + @endpoint.accept(&method(:accept)) + task.children.each(&:wait) + end end end end