Created
January 2, 2011 20:54
-
-
Save igrigorik/762807 to your computer and use it in GitHub Desktop.
Fixes hanging fork processes god issue on 1.9.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/thread.c | |
+++ b/thread.c | |
@@ -391,12 +391,21 @@ thread_cleanup_func_before_exec(void th_ptr) | |
} | |
static void | |
-thread_cleanup_func(void th_ptr) | |
+thread_cleanup_func(void *th_ptr, int atfork) | |
{ | |
rb_thread_t *th = th_ptr; | |
th->locking_mutex = Qfalse; | |
thread_cleanup_func_before_exec(th_ptr); | |
+ | |
+ / | |
+ * Unfortunately, we can't release native threading resource at fork | |
+ * because libc may have unstable locking state therefore touching | |
+ * a threading resource may cause a deadlock. | |
+ */ | |
+ if (atfork) | |
+ return; | |
+ | |
native_thread_destroy(th); | |
} | |
@@ -525,7 +534,7 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s | |
ruby_cleanup(state); | |
} | |
else { | |
- thread_cleanup_func(th); | |
+ thread_cleanup_func(th, FALSE); | |
gvl_release(th->vm); | |
} | |
@@ -2780,7 +2789,7 @@ terminate_atfork_i(st_data_t key, st_data_t val, st_data_t current_th) | |
rb_mutex_abandon_all(th->keeping_mutexes); | |
} | |
th->keeping_mutexes = NULL; | |
- thread_cleanup_func(th); | |
+ thread_cleanup_func(th, TRUE); | |
} | |
return ST_CONTINUE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This patch fixes hanging forked processes under 1.9.. which is something you run into plenty if you run God + Ruby 1.9.
This patch was not included in ruby1.9.2p136, so you'll have to apply it manually for now.
Ruby-Lang ticket: http://redmine.ruby-lang.org/issues/show/4169
God ticket for Ruby 1.9: https://github.com/mojombo/god/issues#issue/6