Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions raised when using ActionController::Live cause server crash #9604

Merged
merged 1 commit into from Apr 8, 2013
Merged

Exceptions raised when using ActionController::Live cause server crash #9604

merged 1 commit into from Apr 8, 2013

Conversation

sgrif
Copy link
Contributor

@sgrif sgrif commented Mar 7, 2013

Any exceptions that occur in a controller using ActionController::Live would cause the server to either hang with an open socket indefinitely, or immediately crash (depending on whether the server was launched with rails s or directly).

Easiest way to duplicate the issue is to include ActionController::Live, and visit a route that has no associated view, or to call an undefined method. Issue was reproduced with Ruby 1.9.3 as well as 2.0.

Added a catch block in Live to make exception handling work similarly to streaming templates. A redirect to 500.html is issued using a script tag, the stream is closed, and the exception is logged to the terminal.

@@ -116,6 +116,10 @@ def process(name)

begin
super(name)
rescue => e
@_response.stream.write ActionView::Base.streaming_completion_on_exception
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely should not write this. It may not be the case that html is being streamed.

@rafaelfranca
Copy link
Member

cc @tenderlove

@sgrif
Copy link
Contributor Author

sgrif commented Mar 8, 2013

@josevalim Changed to only return the html redirect for html requests. Am I correct in assuming we want a plaintext error output otherwise?

@josevalim
Copy link
Contributor

@sgrif I don't think we should output anything at all. For server sent events, there is nothing we could output that would make sense. Even more, the failure could even be due to errors in the socket, so pushing anything could just make things worse. Maybe we would provide a on_error callback in the response stream that users could customize, but i don't think we should do anything out the box.

@sgrif
Copy link
Contributor Author

sgrif commented Mar 9, 2013

@josevalim Both of those make sense, I'll just need to make sure that an error in the on_error block doesn't cause additional problems. It seems like it might not be immediately apparent that all requests to a controller using Live are streamed, even if you're just rendering a view as normal. Do you think it would make sense to only stream when stream.write is called directly from the controller, or if stream: true is passed to render? If not, we should probable change the wording in the documentation from "all actions in that controller will be able to stream" to "all actions will stream"

@sgrif
Copy link
Contributor Author

sgrif commented Mar 17, 2013

@josevalim I've made the changes requested.

@sikachu
Copy link
Member

sikachu commented Mar 18, 2013

@sgrif would you mind rebasing this against master and force push to your branch again? It's not mergeable right now. Thanks!

Any exceptions that occured at the view or controller level for a
controller using ActionController::Live would cause the server to either
hang with an open socket indefinitely, or immediately crash (depending
on whether the server was launched with rails s or directly). Changed
the behavior of exceptions to act the same as streaming templates for
html requests, and allow for an on_error callback if needed.
@sgrif
Copy link
Contributor Author

sgrif commented Mar 18, 2013

@sikachu Sure. I squashed down to a single commit as well.

@geopet
Copy link

geopet commented Mar 28, 2013

Just checking in on this PR. I'm curious to know what are necessary next steps before this can be merged.

@guilleiguaran
Copy link
Member

/cc @josevalim

@ghost ghost assigned josevalim Mar 29, 2013
@tenderlove
Copy link
Member

This seems good to me. @josevalim?

rafaelfranca added a commit that referenced this pull request Apr 8, 2013
Exceptions raised when using ActionController::Live cause server crash
@rafaelfranca rafaelfranca merged commit 63f7356 into rails:master Apr 8, 2013
begin
@_response.stream.write(ActionView::Base.streaming_completion_on_exception) if request.format == :html
@_response.stream.call_on_error
rescue => exceptionception
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a reference to the movie Inception (exception handler within an exception handler)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol. Fixed. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants