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

Broken under rails 2.3.6, 2.3.7 and 2.3.8 (with fix)

minaguib opened this issue · comments

Commit http://github.com/rails/rails/commit/841c01fa0fa92aa6e3c2e5029444a9cbb4f161f3 in rails broken spawn, which makes it behave weird in rails 2.3.6 onwards

Below is a simple fix:
--- a/vendor/plugins/spawn/lib/patches.rb
+++ b/vendor/plugins/spawn/lib/patches.rb
@@ -4,8 +4,13 @@ class ActiveRecord::Base
if Spawn::RAILS_2_2
def self.spawn_reconnect(klass=self)
# keep ancestors' connection_handlers around to avoid them being garbage collected
- (@@ancestor_connection_handlers ||= []) << @@connection_handler
- @@connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
+ if self.respond_to?(:connection_handler)
+ (@@ancestor_connection_handlers ||= []) << self.connection_handler
+ self.connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
+ else
+ (@@ancestor_connection_handlers ||= []) << @@connection_handler
+ @connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
+ end
establish_connection
end
else

The fix is much appreciated. I'll look it over soon.

commented

I use spawn and when I changed to rails 2.3.8 it did nit worked anymore
Then Tom informed me about your patch and when I used it everything worked again, but
that was in my development environment using webbrick
when I changed to the production enviroment using a web-hotel with an Apache and fast cgi server the same problen seems to exist, The spawn do not work it is just silent, in spite of your patch
Is that possible, that the patch doen not work for Apache and fast cgi

commented

I just discussed the problem with the webhotel and they pointed to that they use linux as a possible cause to the problem

Hi Marmolin

Unfortunately your messages don't provide enough info to start debugging your problem. Perhaps you can sprinkle a few logging statements in your installation of spawn to see where it stops working. Concentrate around the area where it does fork()

FWIW, I don't think this current breakage and my patch fixing it are related to your issue, but I could be wrong. My patch simply addresses some changes in rails, specifically http://github.com/rails/rails/commit/841c01fa0fa92aa6e3c2e5029444a9cbb4f161f3 .

commented

Thanks for the answer
When I changed my development environment from 2.3 to rals 2.3.8 spawn just died silently, Then I installed your patch and everything worked again
When I deployed my aplication on a linux apach fast cgi web server that also runs rails 2.3.8 the same thing happened, When I used spawn around some bit of code, nothing happend and the application seemd to die silently without any loggin or error statement
y. RUnning the same part without spawn worked
I will try do do some logging, but in my installation the spawned part of the code does not write any loggin. However i will try again

Here s the result of logging debuggings
start parse and end parse are my loggings and spawn> is the debug logging from the plugin, as shown in the protected method fork_it.
However then it should also log spawn> child ... which it does not
As I am not very good in Ruby I cannot tell what child=fork do means, but if just is a assignment followed by a block then the last child-message should be printed if everything works correctly
Any possible coause of the problem ?

start parse
spawn> parent PID = 31651
end parse
Redirected to http://www.disweb.dis.se/gedcom_files/check_parsing_status/106

protected
def fork_it(options)

The problem with rails is that it only has one connection (per class),

so when we fork a new process, we need to reconnect.

@@logger.debug "spawn> parent PID = #{Process.pid}"
child = fork do
begin
start = Time.now
@@logger.debug "spawn> child PID = #{Process.pid}"

   # set the nice priority if needed
   Process.setpriority(Process::PRIO_PROCESS, 0, options[:nice]) if options[:nice]

   # disconnect from the listening socket, et al
   Spawn.close_resources
   # get a new connection so the parent can keep the original one
   ActiveRecord::Base.spawn_reconnect

   # run the block of code that takes so long
   yield

Is the parent process still running? Perhaps it just stopped logging. Is the child process still logging?

commented

The parent process is still running
The chil dprocess is not logging anything

Thanks for the patch Mina. I have applied a variant of your patch to the edge branch. It seems to work fine for older versions of Rails 2 so I took out the respond_to? check.