Rails i18n 方法导致分段错误?
Rails i18n method results in segmentation fault?
我有一个名为 "StoryPresenter" 的 class,它充当我的模型对象的包装器(class 的一个实例,称为 "Story")并帮助呈现模型的数据我的意见。 StoryPresenter 的实例包含故事的实例,以及以下方法:
def state
if story.school_state_territory.blank?
""
else
" | #{ story.school_state_territory }"
end
end
上述方法工作正常,但是当我添加 Rails i18n 方法并刷新浏览器时,我的 Rails 服务器崩溃了:
def state
if story.school_state_territory.blank?
""
else
" | #{ t(story.school_state_territory) }"
end
end
崩溃后,当我重新启动服务器并刷新浏览器时 i18n 方法仍然存在,页面加载但我看到 HTML 在en.yml 文件中缺少指示给定属性的翻译关键字的页面。预计会出现警告或类似的东西(因为密钥实际上丢失了),但我不希望在这种情况下 Rails 服务器崩溃。
发生崩溃后,我在服务器日志中看到以下输出:
Started GET "/stories/drafts" for ::1 at 2016-06-28 10:48:42 -0400
Processing by StoriesController#drafts as HTML
(eval):1: [BUG] Segmentation fault at 0x00000105353028
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
崩溃报告中的一些相关信息:
Process: ruby [4432]
Path: /Users/USER/*/ruby
Identifier: ruby
Version: 0
Code Type: X86-64 (Native)
Parent Process: bash [2433]
Responsible: Terminal [280]
User ID: 501
Crashed Thread: 2 server.rb:285
Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000105353028
VM Regions Near 0x105353028:
MALLOC_LARGE 000000010529c000-0000000105353000 [ 732K] rw-/rwx SM=PRV
--> VM_ALLOCATE 0000000105353000-0000000105354000 [ 4K] rw-/rwx SM=ALI
MALLOC_LARGE 00000001053a4000-0000000105698000 [ 3024K] rw-/rwx SM=PRV
Thread 2 Crashed:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184bf06 __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff889bd4ec pthread_kill + 90
2 libsystem_c.dylib 0x00007fff91f736e7 abort + 129
3 libruby.2.3.0.dylib 0x00000001040152f9 die + 9
4 libruby.2.3.0.dylib 0x000000010401553e rb_bug_context + 574
5 libruby.2.3.0.dylib 0x00000001040eb773 sigsegv + 83 (signal.c:805)
6 libsystem_platform.dylib 0x00007fff894eb52a _sigtramp + 26
我看到 "Kern_Invalid_Address" 异常代码,这与崩溃的原因有关吗?
Gemfile.lock 这里:
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.6)
actionpack (= 4.2.6)
actionview (= 4.2.6)
activejob (= 4.2.6)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.6)
actionview (= 4.2.6)
activesupport (= 4.2.6)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.6)
activesupport (= 4.2.6)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (4.2.6)
activesupport (= 4.2.6)
globalid (>= 0.3.0)
activemodel (4.2.6)
activesupport (= 4.2.6)
builder (~> 3.1)
activerecord (4.2.6)
activemodel (= 4.2.6)
activesupport (= 4.2.6)
arel (~> 6.0)
activesupport (4.2.6)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
arel (6.0.3)
ast (2.3.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bower-rails (0.10.0)
brakeman (3.3.2)
builder (3.2.2)
bullet (5.1.0)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.10.0)
bundler-audit (0.5.0)
bundler (~> 1.2)
thor (~> 0.18)
byebug (9.0.5)
capybara (2.7.1)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
cliver (0.3.2)
coderay (1.1.1)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.1.x)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.10.0)
concurrent-ruby (1.0.2)
database_cleaner (1.5.3)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
erubis (2.7.0)
eventmachine (1.2.0.1)
execjs (2.7.0)
factory_girl (4.7.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.7.0)
factory_girl (~> 4.7.0)
railties (>= 3.0.0)
ffi (1.9.10)
font-awesome-sass (4.6.2)
sass (>= 3.2)
formatador (0.2.5)
globalid (0.3.6)
activesupport (>= 4.1.0)
guard (2.14.0)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-livereload (2.5.2)
em-websocket (~> 0.5)
guard (~> 2.8)
guard-compat (~> 1.0)
multi_json (~> 1.8)
http_parser.rb (0.6.0)
i18n (0.7.0)
jbuilder (2.5.0)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
jquery-rails (4.1.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
lol_dba (2.0.3)
actionpack (>= 3.0, < 5.0)
activerecord (>= 3.0, < 5.0)
railties (>= 3.0, < 5.0)
loofah (2.0.3)
nokogiri (>= 1.5.9)
lumberjack (1.0.10)
mail (2.6.4)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.9.0)
multi_json (1.12.1)
mysql2 (0.4.4)
nenv (0.3.0)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
notiffany (0.1.0)
nenv (~> 0.1)
shellany (~> 0.0)
parser (2.3.1.2)
ast (~> 2.2)
pkg-config (1.1.7)
poltergeist (1.9.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
powerpack (0.1.1)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.6)
actionmailer (= 4.2.6)
actionpack (= 4.2.6)
actionview (= 4.2.6)
activejob (= 4.2.6)
activemodel (= 4.2.6)
activerecord (= 4.2.6)
activesupport (= 4.2.6)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.6)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.7)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (4.2.6)
actionpack (= 4.2.6)
activesupport (= 4.2.6)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.1.0)
rake (11.2.2)
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
rdoc (4.2.2)
json (~> 1.4)
rspec-core (3.4.4)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-mocks (3.4.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-rails (3.4.2)
actionpack (>= 3.0, < 4.3)
activesupport (>= 3.0, < 4.3)
railties (>= 3.0, < 4.3)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
rubocop (0.40.0)
parser (>= 2.3.1.0, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
ruby_dep (1.3.1)
sass (3.4.22)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
shellany (0.0.1)
shoulda-matchers (3.1.1)
activesupport (>= 4.0.0)
simple_form (3.2.1)
actionpack (> 4, < 5.1)
activemodel (> 4, < 5.1)
slop (3.6.0)
sprockets (3.6.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.0.4)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
teaspoon (1.1.5)
railties (>= 3.2.5, < 6)
teaspoon-mocha (2.3.3)
teaspoon (>= 1.0.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (3.0.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.0.5)
uniform_notifier (1.10.0)
web-console (2.3.0)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
websocket-driver (0.6.4)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
xpath (2.0.0)
nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
bower-rails (~> 0.10.0)
brakeman
bullet (~> 5.1)
bundler-audit
byebug
coffee-rails (~> 4.1.0)
database_cleaner
factory_girl_rails
font-awesome-sass (~> 4.6.2)
guard-livereload (~> 2.5)
jbuilder (~> 2.0)
jquery-rails
lol_dba
mysql2 (>= 0.3.13, < 0.5)
poltergeist
rails (= 4.2.6)
rspec-rails (~> 3.4)
rubocop
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
shoulda-matchers (~> 3.1)
simple_form
teaspoon-mocha
uglifier (>= 1.3.0)
web-console (~> 2.0)
BUNDLED WITH
1.12.5
更新 1:
以下所有线程跟踪:
Thread 0:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff9184c07a __select + 10
1 libruby.2.3.0.dylib 0x0000000104188439 rb_thread_fd_select + 1625 (.thread_pthread.c:1090)
2 libruby.2.3.0.dylib 0x000000010405ad84 select_call + 1188 (io.c:8435)
3 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
4 libruby.2.3.0.dylib 0x0000000104050a5c rb_f_select + 140 (io.c:8853)
5 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
6 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
7 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
8 libruby.2.3.0.dylib 0x0000000104169237 rb_yield + 183 (.vm_eval.c:1028)
9 libruby.2.3.0.dylib 0x000000010407738e rb_obj_tap + 14 (object.c:693)
10 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
11 libruby.2.3.0.dylib 0x000000010415c264 vm_exec_core + 11348 (insns.def:964)
12 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
13 libruby.2.3.0.dylib 0x0000000104021ff0 rb_load_internal0 + 288 (load.c:619)
14 libruby.2.3.0.dylib 0x00000001040228a5 rb_require_internal + 1813 (load.c:998)
15 libruby.2.3.0.dylib 0x0000000104022078 rb_f_require + 24 (load.c:1045)
16 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
17 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
18 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
19 libruby.2.3.0.dylib 0x000000010401e2b8 ruby_exec_internal + 152 (eval.c:250)
20 libruby.2.3.0.dylib 0x000000010401e1c6 ruby_run_node + 54 (eval.c:302)
21 ruby 0x0000000103fc8f2f main + 79 (main.c:36)
22 libdyld.dylib 0x00007fff865675ad start + 1
Thread 1:: ruby-timer-thr
0 libsystem_kernel.dylib 0x00007fff9184d2a2 poll + 10
1 libruby.2.3.0.dylib 0x000000010418c823 thread_timer + 371 (.thread_pthread.c:1458)
2 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
3 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
4 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 2 Crashed:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184bf06 __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff889bd4ec pthread_kill + 90
2 libsystem_c.dylib 0x00007fff91f736e7 abort + 129
3 libruby.2.3.0.dylib 0x00000001040152f9 die + 9
4 libruby.2.3.0.dylib 0x000000010401553e rb_bug_context + 574
5 libruby.2.3.0.dylib 0x00000001040eb773 sigsegv + 83 (signal.c:805)
6 libsystem_platform.dylib 0x00007fff894eb52a _sigtramp + 26
Thread 3:: utils.rb:156
0 libsystem_kernel.dylib 0x00007fff9184bdb6 __psynch_cvwait + 10
1 libsystem_pthread.dylib 0x00007fff889bb728 _pthread_cond_wait + 767
2 libruby.2.3.0.dylib 0x00000001041850a8 native_sleep + 424 (.thread_pthread.c:342)
3 libruby.2.3.0.dylib 0x00000001041856dd rb_thread_sleep_deadly + 173 (thread.c:1062)
4 libruby.2.3.0.dylib 0x000000010418e909 queue_sleep + 9 (.thread_sync.c:767)
5 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
6 libruby.2.3.0.dylib 0x000000010418e6fd queue_do_pop + 173 (ruby.h:2041)
7 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
8 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
9 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
10 libruby.2.3.0.dylib 0x000000010416c594 vm_invoke_proc + 196 (vm.c:1046)
11 libruby.2.3.0.dylib 0x000000010418c557 thread_start_func_2 + 1463 (thread.c:584)
12 libruby.2.3.0.dylib 0x000000010418bf7a thread_start_func_1 + 170 (.thread_pthread.c:882)
13 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
14 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
15 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 4:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184c07a __select + 10
1 libruby.2.3.0.dylib 0x0000000104188439 rb_thread_fd_select + 1625 (.thread_pthread.c:1090)
2 libruby.2.3.0.dylib 0x0000000104188922 select_single + 34 (thread.c:3778)
3 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
4 libruby.2.3.0.dylib 0x000000010418871c rb_wait_for_single_fd + 124 (thread.c:3818)
5 wait.bundle 0x0000000104665db3 io_wait_readable + 131 (wait.c:64)
6 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
7 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
8 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
9 libruby.2.3.0.dylib 0x000000010416c594 vm_invoke_proc + 196 (vm.c:1046)
10 libruby.2.3.0.dylib 0x000000010418c557 thread_start_func_2 + 1463 (thread.c:584)
11 libruby.2.3.0.dylib 0x000000010418bf7a thread_start_func_1 + 170 (.thread_pthread.c:882)
12 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
13 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
14 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 5:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184c07a __select + 10
1 libruby.2.3.0.dylib 0x0000000104188439 rb_thread_fd_select + 1625 (.thread_pthread.c:1090)
2 libruby.2.3.0.dylib 0x0000000104188922 select_single + 34 (thread.c:3778)
3 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
4 libruby.2.3.0.dylib 0x000000010418871c rb_wait_for_single_fd + 124 (thread.c:3818)
5 wait.bundle 0x0000000104665db3 io_wait_readable + 131 (wait.c:64)
6 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
7 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
8 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
9 libruby.2.3.0.dylib 0x000000010416c594 vm_invoke_proc + 196 (vm.c:1046)
10 libruby.2.3.0.dylib 0x000000010418c557 thread_start_func_2 + 1463 (thread.c:584)
11 libruby.2.3.0.dylib 0x000000010418bf7a thread_start_func_1 + 170 (.thread_pthread.c:882)
12 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
13 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
14 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 6:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184c07a __select + 10
1 libruby.2.3.0.dylib 0x0000000104188439 rb_thread_fd_select + 1625 (.thread_pthread.c:1090)
2 libruby.2.3.0.dylib 0x0000000104188922 select_single + 34 (thread.c:3778)
3 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
4 libruby.2.3.0.dylib 0x000000010418871c rb_wait_for_single_fd + 124 (thread.c:3818)
5 wait.bundle 0x0000000104665db3 io_wait_readable + 131 (wait.c:64)
6 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
7 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
8 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
9 libruby.2.3.0.dylib 0x000000010416c594 vm_invoke_proc + 196 (vm.c:1046)
10 libruby.2.3.0.dylib 0x000000010418c557 thread_start_func_2 + 1463 (thread.c:584)
11 libruby.2.3.0.dylib 0x000000010418bf7a thread_start_func_1 + 170 (.thread_pthread.c:882)
12 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
13 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
14 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 7:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184c07a __select + 10
1 libruby.2.3.0.dylib 0x0000000104188439 rb_thread_fd_select + 1625 (.thread_pthread.c:1090)
2 libruby.2.3.0.dylib 0x0000000104188922 select_single + 34 (thread.c:3778)
3 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
4 libruby.2.3.0.dylib 0x000000010418871c rb_wait_for_single_fd + 124 (thread.c:3818)
5 wait.bundle 0x0000000104665db3 io_wait_readable + 131 (wait.c:64)
6 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
7 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
8 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
9 libruby.2.3.0.dylib 0x000000010416c594 vm_invoke_proc + 196 (vm.c:1046)
10 libruby.2.3.0.dylib 0x000000010418c557 thread_start_func_2 + 1463 (thread.c:584)
11 libruby.2.3.0.dylib 0x000000010418bf7a thread_start_func_1 + 170 (.thread_pthread.c:882)
12 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
13 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
14 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 8:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184c07a __select + 10
1 libruby.2.3.0.dylib 0x0000000104188439 rb_thread_fd_select + 1625 (.thread_pthread.c:1090)
2 libruby.2.3.0.dylib 0x0000000104188922 select_single + 34 (thread.c:3778)
3 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
4 libruby.2.3.0.dylib 0x000000010418871c rb_wait_for_single_fd + 124 (thread.c:3818)
5 wait.bundle 0x0000000104665db3 io_wait_readable + 131 (wait.c:64)
6 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
7 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
8 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
9 libruby.2.3.0.dylib 0x000000010416c594 vm_invoke_proc + 196 (vm.c:1046)
10 libruby.2.3.0.dylib 0x000000010418c557 thread_start_func_2 + 1463 (thread.c:584)
11 libruby.2.3.0.dylib 0x000000010418bf7a thread_start_func_1 + 170 (.thread_pthread.c:882)
12 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
13 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
14 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 2 crashed with X86 Thread State (64-bit):
rax: 0x0000000000000000 rbx: 0x0000000000000006 rcx: 0x00007feb6491dff8 rdx: 0x0000000000000000
rdi: 0x0000000000001603 rsi: 0x0000000000000006 rbp: 0x00007feb6491e020 rsp: 0x00007feb6491dff8
r8: 0x0000000000000040 r9: 0x00007fff73c491e0 r10: 0x0000000008000000 r11: 0x0000000000000206
r12: 0x00007feb6491e150 r13: 0x000000000000000a r14: 0x0000700000108000 r15: 0x0000000104209072
rip: 0x00007fff9184bf06 rfl: 0x0000000000000206 cr2: 0x00007fff73c47008
Logical CPU: 0
Error Code: 0x02000148
Trap Number: 133
来自评论:
通过替换找到了解决方法(不是底层错误的解决方案):
" | #{ t(story.school_state_territory) }"
有:
" | #{ t(story.school_state_territory) rescue "" }"
似乎来自 t
的未处理异常导致了导致崩溃的连锁反应。
Ruby 使用 longjmp
在 C 中实现异常,这意味着代码执行链停止并且永远不会 return 到它的原始位置。
在实现服务器时,执行链通常以所谓的 "event loop" 或反应器模式循环。
如果 longjmp
跳出此循环,服务器可能(并且很可能会)崩溃或挂起。
这类似于 Ruby 代码,当不处理任何异常时,将跳回堆栈顶部并可能终止进程 (return)。
因此,在从 C 实现 Ruby 回调时,保护回调不受任何 longjmp
或 Ruby 异常的影响通常很重要。 Ruby MRI为此提供了CAPI(即rb_protect
)。
这同样适用于 FFI。使用 FFI 时,重要的是 "wrap" 在 rescue 语句中进行回调,然后再将它们传递给采用回调的 FFI 函数。
找到回调处理程序(无论是服务器调用 Ruby 来处理请求,还是另一个库,例如后台任务库)并提交错误报告会很有帮助。
我有一个名为 "StoryPresenter" 的 class,它充当我的模型对象的包装器(class 的一个实例,称为 "Story")并帮助呈现模型的数据我的意见。 StoryPresenter 的实例包含故事的实例,以及以下方法:
def state
if story.school_state_territory.blank?
""
else
" | #{ story.school_state_territory }"
end
end
上述方法工作正常,但是当我添加 Rails i18n 方法并刷新浏览器时,我的 Rails 服务器崩溃了:
def state
if story.school_state_territory.blank?
""
else
" | #{ t(story.school_state_territory) }"
end
end
崩溃后,当我重新启动服务器并刷新浏览器时 i18n 方法仍然存在,页面加载但我看到 HTML 在en.yml 文件中缺少指示给定属性的翻译关键字的页面。预计会出现警告或类似的东西(因为密钥实际上丢失了),但我不希望在这种情况下 Rails 服务器崩溃。
发生崩溃后,我在服务器日志中看到以下输出:
Started GET "/stories/drafts" for ::1 at 2016-06-28 10:48:42 -0400
Processing by StoriesController#drafts as HTML
(eval):1: [BUG] Segmentation fault at 0x00000105353028
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
崩溃报告中的一些相关信息:
Process: ruby [4432]
Path: /Users/USER/*/ruby
Identifier: ruby
Version: 0
Code Type: X86-64 (Native)
Parent Process: bash [2433]
Responsible: Terminal [280]
User ID: 501
Crashed Thread: 2 server.rb:285
Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000105353028
VM Regions Near 0x105353028:
MALLOC_LARGE 000000010529c000-0000000105353000 [ 732K] rw-/rwx SM=PRV
--> VM_ALLOCATE 0000000105353000-0000000105354000 [ 4K] rw-/rwx SM=ALI
MALLOC_LARGE 00000001053a4000-0000000105698000 [ 3024K] rw-/rwx SM=PRV
Thread 2 Crashed:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184bf06 __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff889bd4ec pthread_kill + 90
2 libsystem_c.dylib 0x00007fff91f736e7 abort + 129
3 libruby.2.3.0.dylib 0x00000001040152f9 die + 9
4 libruby.2.3.0.dylib 0x000000010401553e rb_bug_context + 574
5 libruby.2.3.0.dylib 0x00000001040eb773 sigsegv + 83 (signal.c:805)
6 libsystem_platform.dylib 0x00007fff894eb52a _sigtramp + 26
我看到 "Kern_Invalid_Address" 异常代码,这与崩溃的原因有关吗?
Gemfile.lock 这里:
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.6)
actionpack (= 4.2.6)
actionview (= 4.2.6)
activejob (= 4.2.6)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.6)
actionview (= 4.2.6)
activesupport (= 4.2.6)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.6)
activesupport (= 4.2.6)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (4.2.6)
activesupport (= 4.2.6)
globalid (>= 0.3.0)
activemodel (4.2.6)
activesupport (= 4.2.6)
builder (~> 3.1)
activerecord (4.2.6)
activemodel (= 4.2.6)
activesupport (= 4.2.6)
arel (~> 6.0)
activesupport (4.2.6)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
arel (6.0.3)
ast (2.3.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bower-rails (0.10.0)
brakeman (3.3.2)
builder (3.2.2)
bullet (5.1.0)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.10.0)
bundler-audit (0.5.0)
bundler (~> 1.2)
thor (~> 0.18)
byebug (9.0.5)
capybara (2.7.1)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
cliver (0.3.2)
coderay (1.1.1)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.1.x)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.10.0)
concurrent-ruby (1.0.2)
database_cleaner (1.5.3)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
erubis (2.7.0)
eventmachine (1.2.0.1)
execjs (2.7.0)
factory_girl (4.7.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.7.0)
factory_girl (~> 4.7.0)
railties (>= 3.0.0)
ffi (1.9.10)
font-awesome-sass (4.6.2)
sass (>= 3.2)
formatador (0.2.5)
globalid (0.3.6)
activesupport (>= 4.1.0)
guard (2.14.0)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-livereload (2.5.2)
em-websocket (~> 0.5)
guard (~> 2.8)
guard-compat (~> 1.0)
multi_json (~> 1.8)
http_parser.rb (0.6.0)
i18n (0.7.0)
jbuilder (2.5.0)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
jquery-rails (4.1.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
lol_dba (2.0.3)
actionpack (>= 3.0, < 5.0)
activerecord (>= 3.0, < 5.0)
railties (>= 3.0, < 5.0)
loofah (2.0.3)
nokogiri (>= 1.5.9)
lumberjack (1.0.10)
mail (2.6.4)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.9.0)
multi_json (1.12.1)
mysql2 (0.4.4)
nenv (0.3.0)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
notiffany (0.1.0)
nenv (~> 0.1)
shellany (~> 0.0)
parser (2.3.1.2)
ast (~> 2.2)
pkg-config (1.1.7)
poltergeist (1.9.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
powerpack (0.1.1)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.6)
actionmailer (= 4.2.6)
actionpack (= 4.2.6)
actionview (= 4.2.6)
activejob (= 4.2.6)
activemodel (= 4.2.6)
activerecord (= 4.2.6)
activesupport (= 4.2.6)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.6)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.7)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (4.2.6)
actionpack (= 4.2.6)
activesupport (= 4.2.6)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.1.0)
rake (11.2.2)
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
rdoc (4.2.2)
json (~> 1.4)
rspec-core (3.4.4)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-mocks (3.4.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-rails (3.4.2)
actionpack (>= 3.0, < 4.3)
activesupport (>= 3.0, < 4.3)
railties (>= 3.0, < 4.3)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
rubocop (0.40.0)
parser (>= 2.3.1.0, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
ruby_dep (1.3.1)
sass (3.4.22)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
shellany (0.0.1)
shoulda-matchers (3.1.1)
activesupport (>= 4.0.0)
simple_form (3.2.1)
actionpack (> 4, < 5.1)
activemodel (> 4, < 5.1)
slop (3.6.0)
sprockets (3.6.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.0.4)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
teaspoon (1.1.5)
railties (>= 3.2.5, < 6)
teaspoon-mocha (2.3.3)
teaspoon (>= 1.0.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (3.0.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.0.5)
uniform_notifier (1.10.0)
web-console (2.3.0)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
websocket-driver (0.6.4)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
xpath (2.0.0)
nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
bower-rails (~> 0.10.0)
brakeman
bullet (~> 5.1)
bundler-audit
byebug
coffee-rails (~> 4.1.0)
database_cleaner
factory_girl_rails
font-awesome-sass (~> 4.6.2)
guard-livereload (~> 2.5)
jbuilder (~> 2.0)
jquery-rails
lol_dba
mysql2 (>= 0.3.13, < 0.5)
poltergeist
rails (= 4.2.6)
rspec-rails (~> 3.4)
rubocop
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
shoulda-matchers (~> 3.1)
simple_form
teaspoon-mocha
uglifier (>= 1.3.0)
web-console (~> 2.0)
BUNDLED WITH
1.12.5
更新 1:
以下所有线程跟踪:
Thread 0:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff9184c07a __select + 10
1 libruby.2.3.0.dylib 0x0000000104188439 rb_thread_fd_select + 1625 (.thread_pthread.c:1090)
2 libruby.2.3.0.dylib 0x000000010405ad84 select_call + 1188 (io.c:8435)
3 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
4 libruby.2.3.0.dylib 0x0000000104050a5c rb_f_select + 140 (io.c:8853)
5 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
6 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
7 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
8 libruby.2.3.0.dylib 0x0000000104169237 rb_yield + 183 (.vm_eval.c:1028)
9 libruby.2.3.0.dylib 0x000000010407738e rb_obj_tap + 14 (object.c:693)
10 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
11 libruby.2.3.0.dylib 0x000000010415c264 vm_exec_core + 11348 (insns.def:964)
12 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
13 libruby.2.3.0.dylib 0x0000000104021ff0 rb_load_internal0 + 288 (load.c:619)
14 libruby.2.3.0.dylib 0x00000001040228a5 rb_require_internal + 1813 (load.c:998)
15 libruby.2.3.0.dylib 0x0000000104022078 rb_f_require + 24 (load.c:1045)
16 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
17 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
18 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
19 libruby.2.3.0.dylib 0x000000010401e2b8 ruby_exec_internal + 152 (eval.c:250)
20 libruby.2.3.0.dylib 0x000000010401e1c6 ruby_run_node + 54 (eval.c:302)
21 ruby 0x0000000103fc8f2f main + 79 (main.c:36)
22 libdyld.dylib 0x00007fff865675ad start + 1
Thread 1:: ruby-timer-thr
0 libsystem_kernel.dylib 0x00007fff9184d2a2 poll + 10
1 libruby.2.3.0.dylib 0x000000010418c823 thread_timer + 371 (.thread_pthread.c:1458)
2 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
3 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
4 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 2 Crashed:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184bf06 __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff889bd4ec pthread_kill + 90
2 libsystem_c.dylib 0x00007fff91f736e7 abort + 129
3 libruby.2.3.0.dylib 0x00000001040152f9 die + 9
4 libruby.2.3.0.dylib 0x000000010401553e rb_bug_context + 574
5 libruby.2.3.0.dylib 0x00000001040eb773 sigsegv + 83 (signal.c:805)
6 libsystem_platform.dylib 0x00007fff894eb52a _sigtramp + 26
Thread 3:: utils.rb:156
0 libsystem_kernel.dylib 0x00007fff9184bdb6 __psynch_cvwait + 10
1 libsystem_pthread.dylib 0x00007fff889bb728 _pthread_cond_wait + 767
2 libruby.2.3.0.dylib 0x00000001041850a8 native_sleep + 424 (.thread_pthread.c:342)
3 libruby.2.3.0.dylib 0x00000001041856dd rb_thread_sleep_deadly + 173 (thread.c:1062)
4 libruby.2.3.0.dylib 0x000000010418e909 queue_sleep + 9 (.thread_sync.c:767)
5 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
6 libruby.2.3.0.dylib 0x000000010418e6fd queue_do_pop + 173 (ruby.h:2041)
7 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
8 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
9 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
10 libruby.2.3.0.dylib 0x000000010416c594 vm_invoke_proc + 196 (vm.c:1046)
11 libruby.2.3.0.dylib 0x000000010418c557 thread_start_func_2 + 1463 (thread.c:584)
12 libruby.2.3.0.dylib 0x000000010418bf7a thread_start_func_1 + 170 (.thread_pthread.c:882)
13 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
14 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
15 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 4:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184c07a __select + 10
1 libruby.2.3.0.dylib 0x0000000104188439 rb_thread_fd_select + 1625 (.thread_pthread.c:1090)
2 libruby.2.3.0.dylib 0x0000000104188922 select_single + 34 (thread.c:3778)
3 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
4 libruby.2.3.0.dylib 0x000000010418871c rb_wait_for_single_fd + 124 (thread.c:3818)
5 wait.bundle 0x0000000104665db3 io_wait_readable + 131 (wait.c:64)
6 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
7 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
8 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
9 libruby.2.3.0.dylib 0x000000010416c594 vm_invoke_proc + 196 (vm.c:1046)
10 libruby.2.3.0.dylib 0x000000010418c557 thread_start_func_2 + 1463 (thread.c:584)
11 libruby.2.3.0.dylib 0x000000010418bf7a thread_start_func_1 + 170 (.thread_pthread.c:882)
12 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
13 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
14 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 5:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184c07a __select + 10
1 libruby.2.3.0.dylib 0x0000000104188439 rb_thread_fd_select + 1625 (.thread_pthread.c:1090)
2 libruby.2.3.0.dylib 0x0000000104188922 select_single + 34 (thread.c:3778)
3 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
4 libruby.2.3.0.dylib 0x000000010418871c rb_wait_for_single_fd + 124 (thread.c:3818)
5 wait.bundle 0x0000000104665db3 io_wait_readable + 131 (wait.c:64)
6 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
7 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
8 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
9 libruby.2.3.0.dylib 0x000000010416c594 vm_invoke_proc + 196 (vm.c:1046)
10 libruby.2.3.0.dylib 0x000000010418c557 thread_start_func_2 + 1463 (thread.c:584)
11 libruby.2.3.0.dylib 0x000000010418bf7a thread_start_func_1 + 170 (.thread_pthread.c:882)
12 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
13 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
14 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 6:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184c07a __select + 10
1 libruby.2.3.0.dylib 0x0000000104188439 rb_thread_fd_select + 1625 (.thread_pthread.c:1090)
2 libruby.2.3.0.dylib 0x0000000104188922 select_single + 34 (thread.c:3778)
3 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
4 libruby.2.3.0.dylib 0x000000010418871c rb_wait_for_single_fd + 124 (thread.c:3818)
5 wait.bundle 0x0000000104665db3 io_wait_readable + 131 (wait.c:64)
6 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
7 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
8 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
9 libruby.2.3.0.dylib 0x000000010416c594 vm_invoke_proc + 196 (vm.c:1046)
10 libruby.2.3.0.dylib 0x000000010418c557 thread_start_func_2 + 1463 (thread.c:584)
11 libruby.2.3.0.dylib 0x000000010418bf7a thread_start_func_1 + 170 (.thread_pthread.c:882)
12 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
13 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
14 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 7:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184c07a __select + 10
1 libruby.2.3.0.dylib 0x0000000104188439 rb_thread_fd_select + 1625 (.thread_pthread.c:1090)
2 libruby.2.3.0.dylib 0x0000000104188922 select_single + 34 (thread.c:3778)
3 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
4 libruby.2.3.0.dylib 0x000000010418871c rb_wait_for_single_fd + 124 (thread.c:3818)
5 wait.bundle 0x0000000104665db3 io_wait_readable + 131 (wait.c:64)
6 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
7 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
8 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
9 libruby.2.3.0.dylib 0x000000010416c594 vm_invoke_proc + 196 (vm.c:1046)
10 libruby.2.3.0.dylib 0x000000010418c557 thread_start_func_2 + 1463 (thread.c:584)
11 libruby.2.3.0.dylib 0x000000010418bf7a thread_start_func_1 + 170 (.thread_pthread.c:882)
12 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
13 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
14 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 8:: server.rb:285
0 libsystem_kernel.dylib 0x00007fff9184c07a __select + 10
1 libruby.2.3.0.dylib 0x0000000104188439 rb_thread_fd_select + 1625 (.thread_pthread.c:1090)
2 libruby.2.3.0.dylib 0x0000000104188922 select_single + 34 (thread.c:3778)
3 libruby.2.3.0.dylib 0x000000010401f289 rb_ensure + 169 (eval.c:901)
4 libruby.2.3.0.dylib 0x000000010418871c rb_wait_for_single_fd + 124 (thread.c:3818)
5 wait.bundle 0x0000000104665db3 io_wait_readable + 131 (wait.c:64)
6 libruby.2.3.0.dylib 0x00000001041736fa vm_call_cfunc + 314 (.vm_insnhelper.c:1638)
7 libruby.2.3.0.dylib 0x000000010415c4c0 vm_exec_core + 11952 (insns.def:995)
8 libruby.2.3.0.dylib 0x000000010416dd4c vm_exec + 124 (vm.c:1650)
9 libruby.2.3.0.dylib 0x000000010416c594 vm_invoke_proc + 196 (vm.c:1046)
10 libruby.2.3.0.dylib 0x000000010418c557 thread_start_func_2 + 1463 (thread.c:584)
11 libruby.2.3.0.dylib 0x000000010418bf7a thread_start_func_1 + 170 (.thread_pthread.c:882)
12 libsystem_pthread.dylib 0x00007fff889ba99d _pthread_body + 131
13 libsystem_pthread.dylib 0x00007fff889ba91a _pthread_start + 168
14 libsystem_pthread.dylib 0x00007fff889b8351 thread_start + 13
Thread 2 crashed with X86 Thread State (64-bit):
rax: 0x0000000000000000 rbx: 0x0000000000000006 rcx: 0x00007feb6491dff8 rdx: 0x0000000000000000
rdi: 0x0000000000001603 rsi: 0x0000000000000006 rbp: 0x00007feb6491e020 rsp: 0x00007feb6491dff8
r8: 0x0000000000000040 r9: 0x00007fff73c491e0 r10: 0x0000000008000000 r11: 0x0000000000000206
r12: 0x00007feb6491e150 r13: 0x000000000000000a r14: 0x0000700000108000 r15: 0x0000000104209072
rip: 0x00007fff9184bf06 rfl: 0x0000000000000206 cr2: 0x00007fff73c47008
Logical CPU: 0
Error Code: 0x02000148
Trap Number: 133
来自评论:
通过替换找到了解决方法(不是底层错误的解决方案):
" | #{ t(story.school_state_territory) }"
有:
" | #{ t(story.school_state_territory) rescue "" }"
似乎来自 t
的未处理异常导致了导致崩溃的连锁反应。
Ruby 使用 longjmp
在 C 中实现异常,这意味着代码执行链停止并且永远不会 return 到它的原始位置。
在实现服务器时,执行链通常以所谓的 "event loop" 或反应器模式循环。
如果 longjmp
跳出此循环,服务器可能(并且很可能会)崩溃或挂起。
这类似于 Ruby 代码,当不处理任何异常时,将跳回堆栈顶部并可能终止进程 (return)。
因此,在从 C 实现 Ruby 回调时,保护回调不受任何 longjmp
或 Ruby 异常的影响通常很重要。 Ruby MRI为此提供了CAPI(即rb_protect
)。
这同样适用于 FFI。使用 FFI 时,重要的是 "wrap" 在 rescue 语句中进行回调,然后再将它们传递给采用回调的 FFI 函数。
找到回调处理程序(无论是服务器调用 Ruby 来处理请求,还是另一个库,例如后台任务库)并提交错误报告会很有帮助。