ajndkr / lanarky

The web framework for building LLM microservices
https://lanarky.ajndkr.com/
MIT License
975 stars 74 forks source link

Fix ramdom Unexpected ASGI message to appear #18

Closed Tooflex closed 1 year ago

Tooflex commented 1 year ago

I asked ChatGPT what might cause the issue and here is the answer:

The BaseLangchainStreamingResponse class uses the async and await keywords to execute asynchronous code. When you use asynchronous programming, multiple coroutines can execute concurrently, meaning that different parts of your application may execute simultaneously. This can lead to race conditions where different coroutines try to modify the same data at the same time.

In this case, it is possible that multiple coroutines are trying to send response messages concurrently, which can cause the 'Unexpected ASGI message' error message to appear. To fix this issue, you can try synchronizing access to the send function by using a lock.

Fixes ajndkr/fastapi-async-langchain#17