2012-06-15 29 views
5

Tôi đã được đưa vào một codebase cũ để nâng cấp nó từ Rails 2.4/Ruby 1.8.7 lên Rails 3.1/Ruby 1.9.2. Trong khi làm điều này, tôi tìm thấy một vấn đề rất thú vị mất 3 ngày để cố gắng tìm ra. Tôi muốn thả nó ở đây cả để cung cấp cho nó một số nước trái cây Google cho người khác nhìn thấy vấn đề, và để đặt câu hỏi: Tại sao?SystemStackError ở cấp độ rack trong Ruby 1.9.2, không 1.8.7

Về cơ bản, tôi đã thấy số SystemStackError ở cấp Rack khi chạy ứng dụng của tôi. Tôi không thể nhận được bất kỳ yêu cầu nào thông qua trước khi lỗi xảy ra và không thể gỡ lỗi vì mã của tôi chưa bao giờ được chạm vào. Trong chế độ phát triển, tôi sẽ có thể thấy nhiều trang web, sau đó đột nhiên sẽ nhận được SystemStackError khi cơ sở dữ liệu bị trúng. Vì vậy, tôi figured nó là một cái gì đó lười biếng tải.

Chuyển sang chế độ sản xuất và ngoại lệ xảy ra theo yêu cầu đầu tiên. Máy chủ khởi động bình thường, nhưng không có yêu cầu nào vượt qua được, và mã của tôi không được chạm vào.

nhanh về phía trước quá nhiều giờ, và tôi đã theo dõi các traceback đến một vòng lặp trong Rails (full gist):

/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_dispatch/routing/url_for.rb:102:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_controller/metal.rb:140:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/abstract_controller/rendering.rb:74:in `initialize' 
/Users/john/.rvm/gems/ruby-1.9.2-p32[email protected]/gems/actionpack-3.1.6/lib/abstract_controller/layouts.rb:301:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_dispatch/routing/url_for.rb:103:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_controller/metal.rb:140:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/abstract_controller/rendering.rb:74:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/abstract_controller/layouts.rb:301:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_dispatch/routing/url_for.rb:103:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_controller/metal.rb:140:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/abstract_controller/rendering.rb:74:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/abstract_controller/layouts.rb:301:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_dispatch/routing/url_for.rb:103:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_controller/metal.rb:140:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/abstract_controller/rendering.rb:74:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/abstract_controller/layouts.rb:301:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_dispatch/routing/url_for.rb:103:in `initialize' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_controller/metal.rb:238:in `new' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_controller/metal.rb:238:in `block in action' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_dispatch/routing/route_set.rb:71:in `call' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_dispatch/routing/route_set.rb:71:in `dispatch' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_dispatch/routing/route_set.rb:35:in `call' 
/Users/john/.rvm/gems/[email protected]/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:152:in `block in call' 
/Users/john/.rvm/gems/[email protected]/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:96:in `block in recognize' 
/Users/john/.rvm/gems/[email protected]/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:68:in `optimized_each' 
/Users/john/.rvm/gems/[email protected]/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:95:in `recognize' 
/Users/john/.rvm/gems/[email protected]/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:141:in `call' 
/Users/john/.rvm/gems/[email protected]/gems/actionpack-3.1.6/lib/action_dispatch/routing/route_set.rb:538:in `call' 
/Users/john/.rvm/gems/[email protected]/gems/omniauth-1.1.0/lib/omniauth/builder.rb:48:in `call' 
... 

Những gì chúng ta thấy ở đây các hệ thống đi xe đạp từ metal.rb để url_for.rb để layouts.rb-rendering.rb đến là metal.rb để url_for.rb, vv

Sau nỗ lực đáng kể, tôi theo dõi này xuống dòng sau ở phía trên cùng của một tập tin mô hình (like so):

012.351.
include ActionView::Helpers::UrlHelpers 

Lưu ý, đây không phải là bên trong lớp, ở cấp mô-đun.

Điều thú vị là hoạt động trong Ruby 1.8.7 nhưng gây ra SystemStackError trong Ruby 1.9.2.

Tôi đã tạo một Github repository illustrating this behavior.

Nếu bạn lấy kho lưu trữ này và chạy chi nhánh ruby18, bạn có thể tải trang. Nếu bạn chạy chi nhánh ruby19, bạn sẽ nhận được một SystemStackError theo bất kỳ yêu cầu nào (bất kỳ yêu cầu nào mà Widget được tải, chạy nó trong quá trình sản xuất và nó sẽ không tải được).

Vì vậy, không ai biết tại sao?

Ý tôi là, tôi tưởng tượng nó có liên quan đến cách Ruby tải mô-đun, vì nó dường như không phải là vấn đề gây ra bởi lõi Rails. Mối quan tâm chính của tôi là một câu hỏi liệu đây có phải là một vấn đề bí truyền do các thực hành lập trình lười biếng trong codebase hay không, hoặc nếu nó là một con trỏ đến một vấn đề sâu hơn, hoặc trong Ruby hoặc Rails.

+0

Tôi gặp vấn đề tương tự. Để thêm nhiều hơn một chút ngữ cảnh nếu tôi khởi chạy toàn bộ bộ thử nghiệm, tôi sẽ gặp lỗi này nhưng nếu tôi khởi chạy một thử nghiệm duy nhất thì nó sẽ hoạt động trơn tru. Bất kỳ tin tức về độ phân giải? thx – gicappa

+1

Độ phân giải đối với tôi là xóa '' 'bao gồm ActionView :: Helpers :: UrlHelpers''' đã gây ra vòng lặp. Nếu bạn không có điều đó, sự nghi ngờ của tôi - mà không biết gì về mã của bạn - là có một thứ tương tự. – JohnMetta

+0

Cảm ơn tôi phát hiện ra tôi đã có một ActionView :: Helpers :: TagHelper trong một thử nghiệm. – gicappa

Trả lời

1

Điều này có vẻ như Bug 3144, nói để tham khảo trực tiếp người trợ giúp.

Rails.application.routes.url_helpers 
+0

Tôi đã tìm kiếm, nhưng không tìm thấy. Cảm ơn bạn đã liên kết ở đây. – JohnMetta

Các vấn đề liên quan