tra / spawnling

spawn gem for Rails to easily fork or thread long-running code blocks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Executing in another thread" error under Rails 3 and Oci8

davesmylie opened this issue · comments

I'm running the edge branch of spawn under rails 3, connecting to an oracle database (using ruby-oci8 gem)

Spawn works most of the time, but will often raise an error:

     28:           - precache_portlet_details(:portlet => portlet, :id => record.id)   
  ruby-oci8 (2.0.4) lib/oci8/oci8.rb:287:in`__execute'
  ruby-oci8 (2.0.4) lib/oci8/oci8.rb:287:in `exec'
  ruby-oci8 (2.0.4) lib/oci8/oci8.rb:115:in`exec'
  app/helpers/application_helper.rb:14:in `precache_portlet_details'

The precache_portlet_details method consists of a simple call to render a partial via spawn:

    spawn(:method => :thread)  do
       controller.display_details(:portlet => opts[:portlet],  :cache_only => true)
    end
  end

If I add a sleep(1) in the spawned method, it runs fine 80% of the time, and if I add a sleep(2) it seems to run fine 100% of the time. I can use the sleep(2) as a work around, but would prefer not to....

I'm unable to try spawn using :method => :fork, as I cannot get the spawned block to connect to the database.

The master branch does not yet support Rails 3. Please try the "edge" branch and report back.

Sorry - my bad.

I meant the edge branch.

edit: I can't believe I just typed master in again by accident =/

Specifically, running this against edge branch on https://github.com/davesmylie/spawn which has been changed to allow it to run against Rails 3.0.3 (which has removed ActiveRecord::Base.allow_concurrency in favor of Rails.application.config.allow_concurrency)

I'm not sure if it will fix your particular issue but could you merge the latest change from edge and see if it has any effect on your problem. It could also enable you to use :fork if you're lucky.

Mixed success - I'm still getting the "Executing in another thread" error when using :thread . . . however, :fork is now working without dropping the connection.

I'm happy to use :fork, so I guess this issue can be closed =)

Thanks!