EasyNMT icon indicating copy to clipboard operation
EasyNMT copied to clipboard

[ERROR] Exception in ASGI application

Open TheMY3 opened this issue 2 years ago • 1 comments

I use it for translations and language detection. It works perfect, but sometimes it failed with 500 error and I see in my pod logs this error multiple times:

[2022-05-12 09:01:32 +0000] [21] [ERROR] Exception in ASGI application
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 398, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/usr/local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/usr/local/lib/python3.8/site-packages/fastapi/applications.py", line 199, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.8/site-packages/starlette/applications.py", line 111, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc from None
  File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.8/site-packages/starlette/middleware/cors.py", line 78, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 566, in __call__
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 227, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 41, in app
    response = await func(request)
  File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 201, in app
    raw_response = await run_endpoint_function(
  File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 148, in run_endpoint_function
    return await dependant.call(**values)
  File "/app/main.py", line 55, in translate
    x = await async_client.post(BACKEND_URL+'/translate', json=data, timeout=3600)
  File "/usr/local/lib/python3.8/site-packages/http3/client.py", line 392, in post
    return await self.request(
  File "/usr/local/lib/python3.8/site-packages/http3/client.py", line 541, in request
    response = await self.send(
  File "/usr/local/lib/python3.8/site-packages/http3/client.py", line 140, in send
    response = await self.send_handling_redirects(
  File "/usr/local/lib/python3.8/site-packages/http3/client.py", line 177, in send_handling_redirects
    response = await self.dispatch.send(
  File "/usr/local/lib/python3.8/site-packages/http3/dispatch/connection_pool.py", line 130, in send
    raise exc
  File "/usr/local/lib/python3.8/site-packages/http3/dispatch/connection_pool.py", line 120, in send
    response = await connection.send(
  File "/usr/local/lib/python3.8/site-packages/http3/dispatch/connection.py", line 59, in send
    response = await self.h11_connection.send(request, timeout=timeout)
  File "/usr/local/lib/python3.8/site-packages/http3/dispatch/http11.py", line 58, in send
    http_version, status_code, headers = await self._receive_response(timeout)
  File "/usr/local/lib/python3.8/site-packages/http3/dispatch/http11.py", line 130, in _receive_response
    event = await self._receive_event(timeout)
  File "/usr/local/lib/python3.8/site-packages/http3/dispatch/http11.py", line 161, in _receive_event
    event = self.h11_state.next_event()
  File "/usr/local/lib/python3.8/site-packages/h11/_connection.py", line 439, in next_event
    exc._reraise_as_remote_protocol_error()
  File "/usr/local/lib/python3.8/site-packages/h11/_util.py", line 72, in _reraise_as_remote_protocol_error
    raise self
  File "/usr/local/lib/python3.8/site-packages/h11/_connection.py", line 422, in next_event
    self._process_event(self.their_role, event)
  File "/usr/local/lib/python3.8/site-packages/h11/_connection.py", line 238, in _process_event
    self._cstate.process_event(role, type(event), server_switch_event)
  File "/usr/local/lib/python3.8/site-packages/h11/_state.py", line 238, in process_event
    self._fire_event_triggered_transitions(role, event_type)
  File "/usr/local/lib/python3.8/site-packages/h11/_state.py", line 251, in _fire_event_triggered_transitions
    raise LocalProtocolError(
h11._util.RemoteProtocolError: can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSE

And then in few minutes:

[2022-05-12 09:01:32 +0000] [177642] [INFO] Booting worker with pid: 177642
[2022-05-12 09:01:34 +0000] [177642] [INFO] Started server process [177642]
[2022-05-12 09:01:34 +0000] [177642] [INFO] Waiting for application startup.
[2022-05-12 09:01:34 +0000] [177642] [INFO] Application startup complete.
{"loglevel": "info", "workers": "1", "bind": "0.0.0.0:port", "graceful_timeout": 120, "timeout": 120, "keepalive": 5, "errorlog": "-", "accesslog": "-", "host": "0.0.0.0", "port": "port"}

I run it in k8s, maybe it was the reason.

TheMY3 avatar May 12 '22 09:05 TheMY3

Rebuilding the container (updating pip packages) resolved this error for me.

jkennedyvz avatar Mar 07 '23 23:03 jkennedyvz