Create a gist now

Instantly share code, notes, and snippets.

ruby-oci8 Runtime Error "executing in another thread"
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment