Skip to content

Commit

Permalink
Set encoding for write pipe
Browse files Browse the repository at this point in the history
This fixes the `Encoding::UndefinedConversionError` error for Rails
applications. Rails sets the default encoding to UTF8:
https://github.com/rails/rails/blob/main/railties/lib/rails.rb#L22-L23

We want to set it to Binary but the IO.pipe method only sets it for the
reader, not the writer.
  • Loading branch information
ngan committed Jul 26, 2021
1 parent ba68d31 commit d705a40
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/bootsnap/cli/worker_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ class Worker

def initialize(jobs)
@jobs = jobs
@pipe_out, @to_io = IO.pipe
@pipe_out, @to_io = IO.pipe(binmode: true)
# Set the writer encoding to binary since IO.pipe only sets it for the reader.
# https://github.com/rails/rails/issues/16514#issuecomment-52313290
@to_io.set_encoding(Encoding::BINARY)

@pid = nil
end

Expand Down

0 comments on commit d705a40

Please sign in to comment.