Skip to content

fix(log): serialize writes to an IO logger so lines from several threads don't mix on JRuby - #683

Merged
route merged 1 commit into
mainfrom
fix/log-thread-safe-puts
Oct 26, 2026
Merged

route merged 1 commit into
mainfrom
fix/log-thread-safe-puts

Conversation

@route

@route route commented Oct 26, 2026

Copy link
Copy Markdown
Member

On JRuby, spec/browser_spec.rb:149 (FERRUM_LOG_FORMAT=json) failed with a line that held two CDP messages mixed together (run).

Log#write calls logger.puts from several threads: sent from the caller or writer thread, received from each WebSocket reader thread, browser from the process output thread. MRI's GVL makes StringIO#puts effectively atomic, JRuby has no GVL, so concurrent writes interleave and corrupt lines.

The line is now built outside a mutex and only puts runs inside it. A Logger already synchronizes itself, so that path is unchanged. The new unit spec fails on JRuby without the fix.

…ads don't mix on JRuby

CDP messages are logged from the caller or writer thread when sent and from the WebSocket reader thread when
received, browser output from the process output thread. On JRuby, without a GVL, concurrent StringIO#puts
calls interleave and corrupt lines. Logger instances already synchronize, so only the puts path is locked.
@route
route merged commit 88a7785 into main Oct 26, 2026
7 checks passed
@route
route deleted the fix/log-thread-safe-puts branch October 26, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant