Skip to content

Commit 3413d29

Browse files
jpcamararosa
authored andcommitted
Fix encoding error in sqlite
* When `Socket.gethostname` returns a hostname with a special character like apostrophe in `Basecamp’s-Computer`, an encoding error is raised `Encoding::UndefinedConversionError: "\xE2" from ASCII-8BIT to UTF-8` * By forcing a utf-8 encoding, the error goes away and the process row properly inserts. * A similar issue occurred in the newrelic ruby gem, and required the same solution newrelic/newrelic-ruby-agent@e1f65a8
1 parent bf6bcf2 commit 3413d29

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/solid_queue/processes/registrable.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def kind
5555
end
5656

5757
def hostname
58-
@hostname ||= Socket.gethostname
58+
@hostname ||= Socket.gethostname.force_encoding(Encoding::UTF_8)
5959
end
6060

6161
def process_pid

test/models/solid_queue/process_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "test_helper"
2+
require "minitest/mock"
23

34
class SolidQueue::ProcessTest < ActiveSupport::TestCase
45
test "prune processes with expired heartbeats" do
@@ -13,4 +14,15 @@ class SolidQueue::ProcessTest < ActiveSupport::TestCase
1314
SolidQueue::Process.prune
1415
end
1516
end
17+
18+
test "hostname's with special characters are properly loaded" do
19+
worker = SolidQueue::Worker.new(queues: "*", threads: 3, polling_interval: 0.2)
20+
hostname = "Basecamp’s-Computer"
21+
22+
Socket.stub :gethostname, hostname.force_encoding("ASCII-8BIT") do
23+
worker.start
24+
wait_for_registered_processes(1, timeout: 1.second)
25+
assert_equal hostname, SolidQueue::Process.last.hostname
26+
end
27+
end
1628
end

0 commit comments

Comments
 (0)