public
Last active

ruby-oci8 Runtime Error "executing in another thread"

  • Download Gist
ruby_oci8_timeout_bug.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
# This will trigger Runtime Error "executing in another thread" from ruby-oci8
# The cause is Timeout interrupted the rb_thread_blocking_region() and causing
# oci8_unblock_func() to be run, however, svcctx->executing_thread is not set
# to nil, causing the client to get into a bad state.
# See http://rubyforge.org/forum/forum.php?thread_id=50112&forum_id=1078
 
require 'rubygems'
require 'oci8'
require 'timeout'
 
puts "Create DB Connection"
conn = OCI8.new('user', 'pass', 'db')
conn.non_blocking = true
 
puts "1111111111111111111111111111111"
cursor = conn.exec('long db execution to cause timeout')
 
begin
Timeout.timeout(1) do
puts "fetching..."
while r = cursor.fetch
end
end
rescue Timeout::Error
puts "DB Timed out"
ensure
puts "Closing cursor"
cursor.close
puts "Cursor is closed"
end
 
puts "22222222222222222222222222222222"
cursor = conn.exec('long db execution to cause timeout')
 
puts "start fetching..."
while r = cursor.fetch
 
end
 
puts "close cursor"
cursor.close

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.