Azure / azure-functions-python-library

Azure Functions Python SDK
MIT License
151 stars 63 forks source link

[BUG] AsgiMiddleware starts an event loop which is never closed #164

Closed ghost closed 1 year ago

ghost commented 1 year ago

Timestamp: Tue 31 Oct 2022 10:45 CET Python azure-functions v1.10

The current AsgiMiddleware class starts a new event loop in its constructor. As can be seen here:

https://github.com/Azure/azure-functions-python-library/blob/8fb366baee8851c6dc1056ccede512694b3bcc70/azure/functions/_http_asgi.py#L149

The deprecated handle() method was responsible for closing this loop once a request was handled.

A better handle_async() method replaced this solution and was introduced here:

https://github.com/Azure/azure-functions-python-library/pull/143/files

But the new solution does not use and never closes the loop created in the constructor

Expected behavior

Starting an event loop is not trivial and opens file resources. These won't be closed when using the new solution. When using the handle_async method there is no need to start a new event loop. If an event loop is needed for backward compatibility in the deprecated handle method, it should be created and stopped in the deprecated method and not in the init.

ramya894 commented 1 year ago

@roekoe-loterij We are investigating on the above issue, will update you with the fix soon. Thanks.

tonybaloney commented 1 year ago

Submitted a fix to the library repo.

Thanks for the report.