AttributeError: 'NoneType' object has no attribute 'call_soon'

Hi! I have the function which gets file from s3 bucket

async def get_object(self, file_path: str) -> Optional[bytes]:
        async with self.session.client(self.SERVICE_NAME) as s3:
                s3_object = await s3.get_object(Bucket=self.BUCKET_NAME, Key=file_path)
            except ClientError:

            async with s3_object["Body"] as stream:
                file_data = await

        return file_data

When my endpoint returned file data and everything is ok, then I get this error

Exception in callback SanicProtocol.abort()
handle: <TimerHandle when=23043869.405625403 SanicProtocol.abort() created at /usr/local/lib/python3.8/site-packages/sanic/server/protocols/>
source_traceback: Object created at (most recent call last):
File “/usr/local/lib/python3.8/site-packages/sanic/server/”, line 199, in serve_single
File “/usr/local/lib/python3.8/site-packages/sanic/server/”, line 150, in serve
File “/usr/local/lib/python3.8/asyncio/”, line 570, in run_forever
File “/usr/local/lib/python3.8/asyncio/”, line 1851, in _run_once
File “/usr/local/lib/python3.8/asyncio/”, line 81, in _run, *self._args)
File “connection_task”, line 35, in connection_task
# request config
File “/usr/local/lib/python3.8/site-packages/sanic/server/protocols/”, line 93, in close
self.loop.call_later(timeout, self.abort)
Traceback (most recent call last):
File “/usr/local/lib/python3.8/asyncio/”, line 81, in _run, *self._args)
File “/usr/local/lib/python3.8/site-packages/sanic/server/protocols/”, line 101, in abort
File “/usr/local/lib/python3.8/asyncio/”, line 672, in abort
File “/usr/local/lib/python3.8/asyncio/”, line 723, in _force_close
self._loop.call_soon(self._call_connection_lost, exc)
AttributeError: ‘NoneType’ object has no attribute ‘call_soon’

What it can be? How can I avoid this error?

What version of Sanic?What does your endpoint look like?

My sanic version is 21.9.1

My endpoint:

async def get_thumbnail_file(_, entity_id: int) -> HTTPResponse:
        entity = await services.fetch_by_id(entity_id)
    except EntityNotFound as err:
        raise exceptions.NotFound(str(err))

    file_data = await get_entity_s3_file(file_path=entity.thumbnail_path)  # <- decoded by means of b64decode
    return json({"file": file_data})

The error doesn’t happen if I use uvloop package, however aerich doesn’t work with uvloop in my case (I use aiomysql package and tortoise orm).

I’ve created command file and use it for migrate and upgrade

import uvloop

from aerich.cli import cli


def main():

if __name__ == "__main__":

I solved my problem, however the error happens if I use asyncio loop instead of uvloop