Skip to content
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

After the user interrupts the stream, a 500 error occurs on the api server. #41

Closed
Riuhou opened this issue Feb 29, 2024 · 4 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@Riuhou
Copy link

Riuhou commented Feb 29, 2024

Describe the bug
Internal Server Error
asyncio.exceptions.CancelledError: Cancelled by cancel scope

Expected behavior
After the front-end user interrupts the stream, a 500 error occurs on the api server.

Desktop (please complete the following information):

  • Server: Ubuntu 22.04.3 LTS
  • Browser chrome
  • Version TaskingAI Community v0.1.3

Additional context

2024-02-29 10:56:55,554 - asyncio - WARNING - socket.send() raised exception.
[2024-02-29 10:56:55 +0000] [9] [ERROR] Exception in ASGI application
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 860, in send_packed_command
await asyncio.wait_for(
File "/usr/local/lib/python3.10/asyncio/tasks.py", line 408, in wait_for
return await fut
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 842, in _send_packed_command
await self._writer.drain()
File "/usr/local/lib/python3.10/asyncio/streams.py", line 371, in drain
await self._protocol._drain_helper()
File "/usr/local/lib/python3.10/asyncio/streams.py", line 167, in _drain_helper
raise ConnectionResetError('Connection lost')
ConnectionResetError: Connection lost

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/usr/local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in call
return await self.app(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in call
await super().call(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/applications.py", line 123, in call
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in call
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.10/site-packages/starlette/middleware/cors.py", line 91, in call
await self.simple_response(scope, receive, send, request_headers=headers)
File "/usr/local/lib/python3.10/site-packages/starlette/middleware/cors.py", line 146, in simple_response
await self.app(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 762, in call
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 782, in app
await route.handle(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 297, in handle
await self.app(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 77, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 72, in app
response = await func(request)
File "/usr/local/lib/python3.10/site-packages/fastapi/routing.py", line 275, in app
solved_result = await solve_dependencies(
File "/usr/local/lib/python3.10/site-packages/fastapi/dependencies/utils.py", line 598, in solve_dependencies
solved = await call(**sub_values)
File "/code/app/routes/utils.py", line 55, in auth_info_required
return await app_admin_auth_info_required(request)
File "/code/app/routes/utils.py", line 27, in app_admin_auth_info_required
admin = await verify_admin_token(token=ret["token"])
File "/code/common/services/auth/admin.py", line 43, in verify_admin_token
admin: Admin = await db_admin.verify_admin_token(token)
File "/code/common/database_ops/auth/admin/verify_token.py", line 29, in verify_admin_token
admin = await get_admin_by_id(admin_id)
File "/code/common/database_ops/auth/admin/get.py", line 12, in get_admin_by_id
admin: Admin = await Admin.get_redis_by_id(admin_id)
File "/code/common/models/auth/admin_user.py", line 56, in get_redis_by_id
return await redis_object_get_object(
File "/code/common/database/redis/management.py", line 83, in redis_object_get_object
value_string = await redis_pool.redis.get(real_key)
File "/usr/local/lib/python3.10/site-packages/aioredis/client.py", line 1084, in execute_command
await conn.send_command(*args)
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 885, in send_command
await self.send_packed_command(
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 868, in send_packed_command
await self.disconnect()
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 806, in disconnect
await self._writer.wait_closed() # type: ignore[union-attr]
File "/usr/local/lib/python3.10/asyncio/streams.py", line 343, in wait_closed
await self._protocol._get_close_waiter(self)
asyncio.exceptions.CancelledError: Cancelled by cancel scope 7feabab2d300
172.19.0.8:56226 - "POST /api/v1/admins/verify_token HTTP/1.1" 500
2024-02-29 10:56:55,907 - asyncio - WARNING - socket.send() raised exception.
[2024-02-29 10:56:55 +0000] [9] [ERROR] Exception in ASGI application
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 860, in send_packed_command
await asyncio.wait_for(
File "/usr/local/lib/python3.10/asyncio/tasks.py", line 408, in wait_for
return await fut
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 842, in _send_packed_command
await self._writer.drain()
File "/usr/local/lib/python3.10/asyncio/streams.py", line 371, in drain
await self._protocol._drain_helper()
File "/usr/local/lib/python3.10/asyncio/streams.py", line 167, in _drain_helper
raise ConnectionResetError('Connection lost')
ConnectionResetError: Connection lost

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/usr/local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in call
return await self.app(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in call
await super().call(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/applications.py", line 123, in call
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in call
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.10/site-packages/starlette/middleware/cors.py", line 83, in call
await self.app(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 762, in call
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 782, in app
await route.handle(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 297, in handle
await self.app(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 77, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 72, in app
response = await func(request)
File "/usr/local/lib/python3.10/site-packages/fastapi/routing.py", line 275, in app
solved_result = await solve_dependencies(
File "/usr/local/lib/python3.10/site-packages/fastapi/dependencies/utils.py", line 598, in solve_dependencies
solved = await call(**sub_values)
File "/code/app/routes/utils.py", line 55, in auth_info_required
return await app_admin_auth_info_required(request)
File "/code/app/routes/utils.py", line 27, in app_admin_auth_info_required
admin = await verify_admin_token(token=ret["token"])
File "/code/common/services/auth/admin.py", line 43, in verify_admin_token
admin: Admin = await db_admin.verify_admin_token(token)
File "/code/common/database_ops/auth/admin/verify_token.py", line 29, in verify_admin_token
admin = await get_admin_by_id(admin_id)
File "/code/common/database_ops/auth/admin/get.py", line 12, in get_admin_by_id
admin: Admin = await Admin.get_redis_by_id(admin_id)
File "/code/common/models/auth/admin_user.py", line 56, in get_redis_by_id
return await redis_object_get_object(
File "/code/common/database/redis/management.py", line 83, in redis_object_get_object
value_string = await redis_pool.redis.get(real_key)
File "/usr/local/lib/python3.10/site-packages/aioredis/client.py", line 1084, in execute_command
await conn.send_command(*args)
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 885, in send_command
await self.send_packed_command(
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 868, in send_packed_command
await self.disconnect()
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 806, in disconnect
await self._writer.wait_closed() # type: ignore[union-attr]
File "/usr/local/lib/python3.10/asyncio/streams.py", line 343, in wait_closed
await self._protocol._get_close_waiter(self)
asyncio.exceptions.CancelledError: Cancelled by cancel scope 7feabab2d300
2024-02-29 10:56:55,909 - asyncio - WARNING - socket.send() raised exception.
172.19.0.8:56238 - "GET /api/v1/models?limit=20&type=text_embedding HTTP/1.1" 500
[2024-02-29 10:56:55 +0000] [9] [ERROR] Exception in ASGI application
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 860, in send_packed_command
await asyncio.wait_for(
File "/usr/local/lib/python3.10/asyncio/tasks.py", line 408, in wait_for
return await fut
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 842, in _send_packed_command
await self._writer.drain()
File "/usr/local/lib/python3.10/asyncio/streams.py", line 371, in drain
await self._protocol._drain_helper()
File "/usr/local/lib/python3.10/asyncio/streams.py", line 167, in _drain_helper
raise ConnectionResetError('Connection lost')
ConnectionResetError: Connection lost

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/usr/local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in call
return await self.app(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in call
await super().call(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/applications.py", line 123, in call
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in call
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.10/site-packages/starlette/middleware/cors.py", line 83, in call
await self.app(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 762, in call
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 782, in app
await route.handle(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 297, in handle
await self.app(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 77, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 72, in app
response = await func(request)
File "/usr/local/lib/python3.10/site-packages/fastapi/routing.py", line 275, in app
solved_result = await solve_dependencies(
File "/usr/local/lib/python3.10/site-packages/fastapi/dependencies/utils.py", line 598, in solve_dependencies
solved = await call(**sub_values)
File "/code/app/routes/utils.py", line 55, in auth_info_required
return await app_admin_auth_info_required(request)
File "/code/app/routes/utils.py", line 27, in app_admin_auth_info_required
admin = await verify_admin_token(token=ret["token"])
File "/code/common/services/auth/admin.py", line 43, in verify_admin_token
admin: Admin = await db_admin.verify_admin_token(token)
File "/code/common/database_ops/auth/admin/verify_token.py", line 29, in verify_admin_token
admin = await get_admin_by_id(admin_id)
File "/code/common/database_ops/auth/admin/get.py", line 12, in get_admin_by_id
admin: Admin = await Admin.get_redis_by_id(admin_id)
File "/code/common/models/auth/admin_user.py", line 56, in get_redis_by_id
return await redis_object_get_object(
File "/code/common/database/redis/management.py", line 83, in redis_object_get_object
value_string = await redis_pool.redis.get(real_key)
File "/usr/local/lib/python3.10/site-packages/aioredis/client.py", line 1084, in execute_command
await conn.send_command(*args)
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 885, in send_command
await self.send_packed_command(
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 868, in send_packed_command
await self.disconnect()
File "/usr/local/lib/python3.10/site-packages/aioredis/connection.py", line 806, in disconnect
await self._writer.wait_closed() # type: ignore[union-attr]
File "/usr/local/lib/python3.10/asyncio/streams.py", line 343, in wait_closed
await self._protocol._get_close_waiter(self)
asyncio.exceptions.CancelledError: Cancelled by cancel scope 7feabab2d300
172.19.0.8:56252 - "GET /api/v1/collections?limit=20 HTTP/1.1" 500

@jameszyao jameszyao self-assigned this Feb 29, 2024
@jameszyao
Copy link
Contributor

@Riuhou thank for the feedback. we'll try to reproduce the error first

@jameszyao jameszyao added the bug Something isn't working label Mar 14, 2024
@YangZhiBoGreenHand
Copy link

image This bug appeared when I was concurrently stress testing, causing the web to log out and then server 500

@jameszyao
Copy link
Contributor

@Riuhou In the v0.2.2 version, we have enhanced the stability of the redis client to avoid continued client downtime. Please check :-)

@Riuhou
Copy link
Author

Riuhou commented Apr 17, 2024

@jameszyao great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants