Rails i18n方法导致分段错误?

时间:2016-06-28 15:21:44

标签: ruby-on-rails c ruby rails-i18n string-interpolation

我有一个名为" StoryPresenter"它充当我的模型对象(一个名为" Story"的类的实例)的包装器,并帮助将模型的数据呈现给我的视图。 StoryPresenter的一个实例包含一个故事的实例,以及以下方法:

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

上面的方法工作正常,但是当我添加Rails i18n方法并刷新浏览器时,我的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]

崩溃后,当我重新启动服务器并刷新浏览器仍然使用i18n方法时,页面会加载,但我看到页面上显示HTML,表示给定的翻译键en.yml文件中缺少该属性。可能会出现警告或类似情况(因为密钥实际上已丢失),但在这种情况下我不会期望Rails服务器崩溃。

崩溃发生后,我在服务器日志中看到以下输出:

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

崩溃报告中的一些相关信息:

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

我看到&#34; Kern_Invalid_Address&#34;异常代码,是否与崩溃的原因有关?

Gemfile.lock here:

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

更新1:

以下所有线程痕迹:

        public IHttpActionResult Post(Candidate candidate)
    {
        try
        {
            if(candidate==null)
                return BadRequest();

            IEnumerable<string> errors;
            _candidateManager.InsertCandidate(candidate, out errors);

            if (errors!=null && errors.Any())
                return BadRequest(CreateErrorMessage("Invalid candidate: ", errors));

            return CreatedAtRoute("DefaultApi", new {id = candidate.CandidateId}, candidate);

        }
        catch (Exception)
        {
            return InternalServerError();
        }
    }

1 个答案:

答案 0 :(得分:1)

来自评论:

通过替换:

找到了一种解决方法(不是基础错误的解决方案)
" | #{ t(story.school_state_territory) }"

使用:

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

似乎来自t的未处理异常导致连锁反应导致崩溃。

Ruby使用longjmp在C中实现异常,这意味着代码执行链停止并且永远不会返回到它的原始位置。

实现服务器时,执行链通常在所谓的“事件循环”或反应器模式中循环。

如果longjmp突然出现此循环,服务器可能(可能会)崩溃或挂起。

这类似于Ruby代码在不处理任何异常时将跳回到堆栈顶部并可能终止进程(返回)。

因此,在从C实现Ruby回调时,保护回调免于任何longjmp或Ruby异常通常很重要。 Ruby MRI为此提供了C API(即rb_protect)。

同样适用于FFI。使用FFI时,在将回调传递给执行回调的FFI函数之前,必须在rescue语句中“回滚”回调。

找到回调处理程序(无论是调用Ruby来处理请求的服务器,还是其他库,例如后台任务库)并提交错误报告都是有益的。