2016-06-28 125 views
0

我有一個名爲「StoryPresenter」的類,它充當我的模型對象(名爲「Story」類的一個實例)的包裝,並幫助將模型的數據呈現給我的視圖。 StoryPresenter的實例包含一個故事的一個實例,以及下面的方法:Rails i18n方法導致分段錯誤?

def state 
    if story.school_state_territory.blank? 
    "" 
    else 
    " | #{ story.school_state_territory }" 
    end 
end 

上述方法工作得很好,但是我的Rails服務器崩潰時,我添加了Rails的國際化方法,並刷新我的瀏覽器:

def state 
    if story.school_state_territory.blank? 
    "" 
    else 
    " | #{ t(story.school_state_territory) }" 
    end 
end 

崩潰後,當我重新啓動服務器並刷新瀏覽器對國際化的方法還是很到位的,頁面加載,但我看到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 
+0

線程2崩潰,因爲它捕捉到分段錯誤信號......這並不一定意味着它是導致分段錯誤的線程(我知道,令人困惑)......你能否將C backtrace粘貼到其他線程以及? – Myst

+0

P.S.可能是'state'函數拋出了一個異常(即't'函數崩潰),導致'longjmp'發生。如果處理不當,這可能會導致連鎖反應,影響其他的東西。嘗試添加一個'確保; 「」行在函數結尾處。 – Myst

+0

添加了C backtraces。 –

回答

1

從評論:

一種解決方法(而不是通過替換髮現了底層錯誤的解決方案) :

" | #{ t(story.school_state_territory) }" 

有了:

" | #{ t(story.school_state_territory) rescue "" }" 

這似乎從t未處理的異常引起了連鎖反應,導致系統崩潰。

Ruby在C中使用longjmp實現異常,這意味着代碼執行鏈將停止並且永不返回到原始位置。

當實現一個服務器時,執行鏈通常被稱爲「事件循環」或反應堆模式。

如果longjmp脫離此循環,服務器可能(也可能會)崩潰或掛起。

這與Ruby代碼在不處理任何異常時將如何跳回堆棧頂部並潛在地終止進程(返回)類似。

因此,從C實現Ruby回調時,保護從任何longjmp或Ruby異常的回調通常很重要。 Ruby MRI爲此提供了C API(即rb_protect)。

這同樣適用於FFI。在使用FFI時,在將回調傳遞給採用回調的FFI功能之前,將回調「包裝」在救援語句中非常重要。

找到回調處理程序(無論是調用Ruby來處理請求的服務器,還是其他庫(如後臺任務庫))並提交錯誤報告都會很有好處。

+0

不熟悉Ruby的底層C實現,我將如何去查找引用的回調處理程序? –

+0

@toomanyrichies,我會回頭看看Ruby代碼,看看是否調用了'state'(也許,用於測試,打印'state' backtraces)...某個點的調用回溯到「first」函數「紅寶石般的土地」這也可能是一個「塊」的調用,而不僅僅是一個函數。如果你沒有寫任何特別的東西,它應該是一個服務器響應塊/回調(一個HTTP請求被傳遞給回調函數,通常是一個Rack'env'變量)或者一個計劃任務(任務本身就是回調函數,它被調度程序調用)。 – Myst