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
Stream handler not closing and causing "too many open files error" #376
Comments
Hello, I think I miss something here. As soon a the kernel shutdown, the container is cleaned, and all instances are destructed. |
I agree that's what should be happening but I don't think it is. I don't think anything is explicitly close/destroying the handler so the stream is left open. The Explicitly closing the Monolog handler via
in our |
I thing you are right about the GC ! I'm a bit reluctant about the |
What are your concerns about using |
Bundle are not really in the DIC. I'll be much easier to Create a new service, and to inject all service tagger monolog.handler in it :)
I don't think so in this situation |
Ok, so would the new service then listen for kernel shutdown events and close the handlers in response to that event? |
Hmmm, looking at it in a bit more detail, it does look like the |
The other way would be to force the gc_collect_cycle() in behat extension (I don't know behat, so I could not really help here) |
Possibly it could be done in Behat (or rather the Behat-Symfony extension) but IMHO components that create/open resources should be responsible for destroying/closing them correctly. It feels like a bit of a sledgehammer for the Behat extension to have to force a GC cycle to clear up after other services (but then I'm not experienced in the Symfony internals, perhaps the Kernel was only ever intended to be used once in a single request and Behat is diverging from that?) |
I think that's why it works in "normal" (i.e. single kernel per request) circumstances but don't think the |
When the https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.destructor This is a demo of the issue. It was created using plain phpunit with Symfony to rule out the potential impacts by the Behat integration. https://github.com/torreytsui/symfony-too-many-open-files-replication |
Just dug a bit and found that Doctrine had the same issue with the database connection resources. They seem to have handled it in the bundle shutdown Not sure if this is a good practice, but would be a good reference. |
More details on the Doctrine's issue thread. doctrine/DoctrineBundle#366 (comment) The reasoning on the approach does make sense to me. What do you think? |
it would make sense to me to iterate over (instantiated) handlers in |
I have come across an issue where when running a significant number of Behat scenarios (260 in my cases) throws a "too many open files error". It looks like this is because the Monolog stream handler is not being closed and as Behat boots a new kernel each time new stream handlers are created (I've checked this using
lsof
and there are definitely an increasing number of file handles to the log file). I think this is the issue referenced in symfony/symfony#26146The issue above references a workaround which does work for me too. However the workaround is a bit of a hack. I'm wondering if the bundle itself should take care of this. In normal working mode, it doesn't cause the problem as there is a single kernel instance per request which gets closed and hence the stream handler is closed as the request is closed. Possibly a tag to identify each handler created and then implementing the
shutdown()
method inMonologBundle
to close any handlers it can find. I can create a PR for this if you feel that approach works.The text was updated successfully, but these errors were encountered: