I am running an instance of this application as part of my own project that sends multiple requests to it in parallel. Although the application works perfectly when responding to one request at a time, it fails when hit with multiple at once, and outputs this to the logs
INFO: 172.19.0.4:59578 - "GET /download/[REDACTED] HTTP/1.1" 500 Internal Server Error
wattpad-downloader | ERROR: Exception in ASGI application
wattpad-downloader | Traceback (most recent call last):
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi
wattpad-downloader | result = await app( # type: ignore[func-returns-value]
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
wattpad-downloader | return await self.app(scope, receive, send)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
wattpad-downloader | await super().__call__(scope, receive, send)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/starlette/applications.py", line 116, in __call__
wattpad-downloader | await self.middleware_stack(scope, receive, send)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 186, in __call__
wattpad-downloader | raise exc
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in __call__
wattpad-downloader | await self.app(scope, receive, _send)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
wattpad-downloader | await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/starlette/_exception_handler.py", line 55, in wrapped_app
wattpad-downloader | raise exc
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/starlette/_exception_handler.py", line 44, in wrapped_app
wattpad-downloader | await app(scope, receive, sender)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 746, in __call__
wattpad-downloader | await route.handle(scope, receive, send)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 288, in handle
wattpad-downloader | await self.app(scope, receive, send)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 75, in app
wattpad-downloader | await wrap_app_handling_exceptions(app, request)(scope, receive, send)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/starlette/_exception_handler.py", line 55, in wrapped_app
wattpad-downloader | raise exc
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/starlette/_exception_handler.py", line 44, in wrapped_app
wattpad-downloader | await app(scope, receive, sender)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 70, in app
wattpad-downloader | response = await func(request)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/fastapi/routing.py", line 299, in app
wattpad-downloader | raise e
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/fastapi/routing.py", line 294, in app
wattpad-downloader | raw_response = await run_endpoint_function(
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
wattpad-downloader | return await dependant.call(**values)
wattpad-downloader | File "/app/main.py", line 30, in download_book
wattpad-downloader | async for title in add_chapters(book, data):
wattpad-downloader | File "/app/create_book.py", line 131, in add_chapters
wattpad-downloader | content = await fetch_part_content(part["id"])
wattpad-downloader | File "/app/create_book.py", line 42, in fetch_part_content
wattpad-downloader | async with session.get(
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 1187, in __aenter__
wattpad-downloader | self._resp = await self._coro
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/aiohttp_client_cache/session.py", line 51, in _request
wattpad-downloader | response, actions = await self.cache.request(
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/aiohttp_client_cache/backends/base.py", line 139, in request
wattpad-downloader | response = None if actions.skip_read else await self.get_response(actions.key)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/aiohttp_client_cache/backends/base.py", line 147, in get_response
wattpad-downloader | response = await self.responses.read(key) or await self._get_redirect_response(str(key))
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/aiohttp_client_cache/backends/base.py", line 169, in _get_redirect_response
wattpad-downloader | redirect_key = await self.redirects.read(key)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/aiohttp_client_cache/backends/sqlite.py", line 180, in read
wattpad-downloader | row = await cursor.fetchone()
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/aiosqlite/cursor.py", line 65, in fetchone
wattpad-downloader | return await self._execute(self._cursor.fetchone)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/aiosqlite/cursor.py", line 40, in _execute
wattpad-downloader | return await self._conn._execute(fn, *args, **kwargs)
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/aiosqlite/core.py", line 133, in _execute
wattpad-downloader | return await future
wattpad-downloader | File "/usr/local/lib/python3.10/site-packages/aiosqlite/core.py", line 106, in run
wattpad-downloader | result = function()
wattpad-downloader | sqlite3.ProgrammingError: Cannot operate on a closed database.