Skip to content

Commit fda9f67

Browse files
committed
Synchronize around modifying hash concurrently
This sometimes caused a spec failure on Rubinius. The problem is that the hash is modified in multiple threads simultanuously. This means that an entry could get lost because of code executed concurrently. This means we have to lock around this to do this safely.
1 parent 3ac5706 commit fda9f67

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

spec/mysql2/client_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,17 @@ def connect *args
293293

294294
it "threaded queries should be supported" do
295295
threads, results = [], {}
296+
lock = Mutex.new
296297
connect = lambda{
297298
Mysql2::Client.new(DatabaseCredentials['root'])
298299
}
299300
Timeout.timeout(0.7) do
300301
5.times {
301302
threads << Thread.new do
302-
results[Thread.current.object_id] = connect.call.query("SELECT sleep(0.5) as result")
303+
result = connect.call.query("SELECT sleep(0.5) as result")
304+
lock.synchronize do
305+
results[Thread.current.object_id] = result
306+
end
303307
end
304308
}
305309
end

0 commit comments

Comments
 (0)