Skip to content

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

@ghost

Description

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:

self._loop = asyncio.new_event_loop()

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions