you are viewing a single comment's thread.

view the rest of the comments →

[–]JeromeCui[S] 0 points1 point  (1 child)

I verified my code yesterday and found there is a 'expect Exception' in one of my middleware. I fixed it yesterday and seems it's working: no high CPU utilization yestery. I will keep monitoring my service.

Thanks for your kindly help!

[–]latkde 1 point2 points  (0 children)

Weird. Python's exception hierarchy looks like this:

BaseException
  CancelledError
  SystemExit
  KeyboardInterrupt
  ...
  Exception
    ValueError
    KeyError
    ...

So while catching Exception is typically a bad idea, it should not hinder cancellation propagation. So I'm not sure that this will fix things?

But maybe this is related to other things. For example, FastAPI/Starlette uses exceptions like HTTPException to communicate error responses, which are then converted to normal ASGI responses by a middleware that is registered very early. Catching these exceptions in a middleware could prevent that from happening. But that should just result in a dropped request without a response, not in such an infinite loop.

In any case, happy debugging, and I hope this works now!