Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
63f7356b
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
63f7356b
编写于
4月 08, 2013
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9604 from sgrif/live_streaming_exceptions
Exceptions raised when using ActionController::Live cause server crash
上级
436d9186
c01d080f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
103 addition
and
1 deletion
+103
-1
actionpack/lib/action_controller/metal/live.rb
actionpack/lib/action_controller/metal/live.rb
+28
-0
actionpack/test/controller/live_stream_test.rb
actionpack/test/controller/live_stream_test.rb
+75
-1
未找到文件。
actionpack/lib/action_controller/metal/live.rb
浏览文件 @
63f7356b
...
...
@@ -56,6 +56,14 @@ def close
super
@buf
.
push
nil
end
def
on_error
(
&
block
)
@error_callback
=
block
end
def
call_on_error
@error_callback
.
call
end
end
class
Response
<
ActionDispatch
::
Response
#:nodoc: all
...
...
@@ -121,6 +129,16 @@ def process(name)
begin
super
(
name
)
rescue
=>
e
begin
@_response
.
stream
.
write
(
ActionView
::
Base
.
streaming_completion_on_exception
)
if
request
.
format
==
:html
@_response
.
stream
.
call_on_error
rescue
=>
exceptionception
log_error
(
exceptionception
)
ensure
log_error
(
e
)
@_response
.
stream
.
close
end
ensure
@_response
.
commit!
end
...
...
@@ -129,6 +147,16 @@ def process(name)
@_response
.
await_commit
end
def
log_error
(
exception
)
logger
=
ActionController
::
Base
.
logger
return
unless
logger
message
=
"
\n
#{
exception
.
class
}
(
#{
exception
.
message
}
):
\n
"
message
<<
exception
.
annoted_source_code
.
to_s
if
exception
.
respond_to?
(
:annoted_source_code
)
message
<<
" "
<<
exception
.
backtrace
.
join
(
"
\n
"
)
logger
.
fatal
(
"
#{
message
}
\n\n
"
)
end
def
response_body
=
(
body
)
super
response
.
stream
.
close
if
response
...
...
actionpack/test/controller/live_stream_test.rb
浏览文件 @
63f7356b
...
...
@@ -52,6 +52,29 @@ def thread_locals
def
with_stale
render
:text
=>
'stale'
if
stale?
(
:etag
=>
"123"
)
end
def
exception_in_view
render
'doesntexist'
end
def
exception_with_callback
response
.
headers
[
'Content-Type'
]
=
'text/event-stream'
response
.
stream
.
on_error
do
response
.
stream
.
write
%(data: "500 Internal Server Error"\n\n)
response
.
stream
.
close
end
raise
'An exception occurred...'
end
def
exception_in_exception_callback
response
.
headers
[
'Content-Type'
]
=
'text/event-stream'
response
.
stream
.
on_error
do
raise
'We need to go deeper.'
end
response
.
stream
.
write
params
[
:widget
][
:didnt_check_for_nil
]
end
end
tests
TestController
...
...
@@ -66,6 +89,21 @@ def build_response
TestResponse
.
new
end
def
assert_stream_closed
assert
response
.
stream
.
closed?
,
'stream should be closed'
end
def
capture_log_output
output
=
StringIO
.
new
old_logger
,
ActionController
::
Base
.
logger
=
ActionController
::
Base
.
logger
,
ActiveSupport
::
Logger
.
new
(
output
)
begin
yield
output
ensure
ActionController
::
Base
.
logger
=
old_logger
end
end
def
test_set_response!
@controller
.
set_response!
(
@request
)
assert_kind_of
(
Live
::
Response
,
@controller
.
response
)
...
...
@@ -119,7 +157,43 @@ def test_live_stream_default_header
def
test_render_text
get
:render_text
assert_equal
'zomg'
,
response
.
body
assert
response
.
stream
.
closed?
,
'stream should be closed'
assert_stream_closed
end
def
test_exception_handling_html
capture_log_output
do
|
output
|
get
:exception_in_view
assert_match
%r((window
\.
location = "/500
\.
html"</script></html>)$)
,
response
.
body
assert_match
'Missing template test/doesntexist'
,
output
.
rewind
&&
output
.
read
assert_stream_closed
end
end
def
test_exception_handling_plain_text
capture_log_output
do
|
output
|
get
:exception_in_view
,
format: :json
assert_equal
''
,
response
.
body
assert_match
'Missing template test/doesntexist'
,
output
.
rewind
&&
output
.
read
assert_stream_closed
end
end
def
test_exception_callback
capture_log_output
do
|
output
|
get
:exception_with_callback
,
format:
'text/event-stream'
assert_equal
%(data: "500 Internal Server Error"\n\n)
,
response
.
body
assert_match
'An exception occurred...'
,
output
.
rewind
&&
output
.
read
assert_stream_closed
end
end
def
test_exceptions_raised_handling_exceptions
capture_log_output
do
|
output
|
get
:exception_in_exception_callback
,
format:
'text/event-stream'
assert_equal
''
,
response
.
body
assert_match
'We need to go deeper'
,
output
.
rewind
&&
output
.
read
assert_stream_closed
end
end
def
test_stale_without_etag
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录