From f23d942cdd8bc732111830c86ec8c4d314eeedb2 Mon Sep 17 00:00:00 2001 From: "Ken C. Demanawa" Date: Tue, 14 Jul 2026 07:53:49 +0800 Subject: [PATCH] Fix logger race before command response delivery - Log websocket responses before pushing them to the waiting command queue so callers cannot observe a completed command before its response has been written to the configured logger. --- lib/ferrum/client/web_socket.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/ferrum/client/web_socket.rb b/lib/ferrum/client/web_socket.rb index 3f8a4de8..acacb31d 100644 --- a/lib/ferrum/client/web_socket.rb +++ b/lib/ferrum/client/web_socket.rb @@ -55,8 +55,6 @@ def on_message(event) # don't push response to @messages. Worse that could happen we raise timeout error due to command didn't return # anything or skip the background notification, but at least we don't crash the thread that crashes the main # thread and the application. - @messages.push(data) if data - output = event.data if SKIP_LOGGING_SCREENSHOTS && @screenshot_commands[data&.dig("id")] @screenshot_commands.delete(data&.dig("id")) @@ -64,6 +62,7 @@ def on_message(event) end @logger&.puts(" ◀ #{Utils::ElapsedTime.elapsed_time} #{output}\n") + @messages.push(data) if data end def on_close(_event)