Ensure all handlers are explicitly closed on kernel shutdown - #377
Conversation
6e7a558 to
5c10161
Compare
lyrixx
left a comment
There was a problem hiding this comment.
I like this PR, but I'm not sure about it. If we do that, we should do the same thing for all others bundle that does IO.
@nicolas-grekas WDYT?
|
Thanks for the comments @lyrixx Have dealt with all of them I think. I notice that Travis has failed for PHP 5.6 and PHP 7.0. Possibly because I used the |
| </service> | ||
|
|
||
| <service id="monolog.handler_manager" class="Symfony\Bundle\MonologBundle\HandlerLifecycleManager" public="true"> | ||
| <argument type="tagged_iterator" tag="monolog.handler" /> |
There was a problem hiding this comment.
Rather than using type="tagged_iterator", you should use a compiler pass to create the IteratorArgument (or drop the tag entirely and manage everything in the DI extension as I don't think we need to support handlers added elsewhere). This way, you can use weak references in the IteratorArgument, which will skip services which haven't been instantiated yet
There was a problem hiding this comment.
I'm not sure I'm familiar enough with the Container to change this right now but given #377 (comment) I should probably pause on this PR now anyway?
|
Regarding a generic solution in symfony, I think we need something similar to the |
954a545 to
af7a879
Compare
|
Rebased the branch onto current 4.x and applied the standing review feedback so it can move forward. The previous structure (root Changes:
stof suggestion implemented: instead of a Added a CHANGELOG entry and tests (handlers are tagged; the manager receives weak references). Local checks: full PHPUnit suite passes, php-cs-fixer is clean. Happy to adjust anything. |
59e91ac to
2adbc6e
Compare
|
Regarding stof's earlier point about a generic Symfony solution: a framework-level mechanism similar to The design is intended to be forward-compatible with that future generic closer: handlers are tagged ( Side note on the service being public: it has to be public because |
2adbc6e to
c184e00
Compare
|
Thanks @andy-educake for working on this feature, this is much appreciated. |
Close all handlers on kernel shutdown. A
HandlerLifecycleManagercloses every already-instantiated handler, including nested ones, through weak references, so unused handlers are not instantiated just to be closed.