From: John Napiorkowski Date: Thu, 2 May 2013 13:29:38 +0000 (-0400) Subject: basic support for delayed writes/async with docs X-Git-Tag: 5.90040~3^2~18 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=717fc5c90d2cbbd6288bae9be82dbd8f6b917bab basic support for delayed writes/async with docs --- diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 2367139..3b7c7fa 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -54,7 +54,22 @@ See L. =head2 $self->finalize_body($c) -Finalize body. Prints the response output. +Finalize body. Prints the response output as blocking stream if it looks like +a filehandle, otherwise write it out all in one go. If there is no body in +the response, we assume you are handling it 'manually', such as for nonblocking +style or asynchronous streaming responses. + +By default we do not close the writer object in case we are in an event loop +and there is deferred activity. However if you have some sloppy code that is +closing over an unweakened context ($c) this could lead to the writer NEVER +being closed. In versions of Catalyst 5.90030 and older, we used to forcibly +close the writer in this method, but we no longer do that since it prevented us +from introducing proper asynchronous support in Catalyst core. If you have old +code that is leaking context but was otherwise working and you don't want to fix +your memory leaks (is really the best idea) you can force enable the old +behavior (and lose asynchronous support) by setting the global configuration key +C to true. See L +for more if you have this issue. =cut @@ -75,9 +90,11 @@ sub finalize_body { $self->write( $c, $body ); } - my $res = $c->response; - $res->_writer->close; - $res->_clear_writer; + if($c->config->{aggressively_close_writer_on_finalize_body}) { + my $res = $c->response; + $res->_writer->close; + $res->_clear_writer; + } return; } diff --git a/lib/Catalyst/Upgrading.pod b/lib/Catalyst/Upgrading.pod index b6d3c8b..1807053 100644 --- a/lib/Catalyst/Upgrading.pod +++ b/lib/Catalyst/Upgrading.pod @@ -2,6 +2,44 @@ Catalyst::Upgrading - Instructions for upgrading to the latest Catalyst +=head1 Upgrading to Catalyst 5.90040 + +This version of L offers some support for using L and +L event loops in your application. In order to achieve this goal +we needed to make some changes to the way the we finalize the HTTP response +such that sloppy code that closed over $c and leaked memory will no longer +work in some manner. For example you might accidently have: + + $c->stash(my_model => sub { $c->model->find(shift) }); + +If you have old code that leaks memory in this way but otherwise seemed to +work, it will no longer complete the response properly. + +If you don't want to fix your code, you can force the old behavior with the +global configuration key C. This +of course will still leave you with a leaky application and you lose the new +event loop support, but your application will go back to completing its +response output. For example: + + package MyApp::Web; + + use Moose; + use Catalyst; + + __PACKAGE__->config( + name => 'MyApp::Web', + enable_catalyst_header => 1, + disable_component_resolution_regex_fallback => 1, + aggressively_close_writer_on_finalize_body => 1, + ); + + __PACKAGE__->setup; + +See L for help on how to close over the +context safely, should you need to do this. See L +and L for help if you want to solve your +memory leak issues. + =head1 Upgrading to Catalyst 5.9 The major change is that L, a toolkit for using the L