sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.
https://sanic.dev
MIT License
18k stars 1.54k forks source link

http1_request_header() error: asyncio.exceptions.CancelledError #2669

Closed niudinlp closed 1 year ago

niudinlp commented 1 year ago

Is there an existing issue for this?

Describe the bug

There is one error in my app server:

image

File "/usr/local/lib/python3.8/site-packages/sanic/http/http1.py", line 123, in http1 await self.http1_request_header() File "http1_request_header", line 18, in http1_request_header ServiceUnavailable, File "/usr/local/lib/python3.8/site-packages/sanic/server/protocols/base_protocol.py", line 82, in receive_more await self._data_received.wait() File "/usr/local/lib/python3.8/asyncio/locks.py", line 309, in wait await fut asyncio.exceptions.CancelledError

Code snippet

app

app = Sanic(name='trait', config=Config(defaults=config))

exception

app.error_handler.add(Exception, handle_exception)

def handle_exception(request, e): traceback.print_exc()

code = ResponseCode.FAIL
message = repr(e)
status = 500
trace_id = request.headers.get("trace_id", None)

logger.error(f"[{trace_id}] service error: {traceback.format_exc()}")
data = {}
if request.app.config.get("DEBUG"):
    data["exception"] = traceback.format_exc()

return response_json(code, message, status, **data)

Expected Behavior

No response

How do you run Sanic?

As a script (app.run or Sanic.serve)

Operating System

Ubuntu 22.04.1 LTS

Sanic Version

22.6.2

Additional context

No response

Tronic commented 1 year ago

Is your server heavily loaded? HTTP 503 ServiceUnavailable would indicate that, probably goes along with those CancellationErrors. But could you add code tags (three backwards ticks before and after code) on your message to make it more readable?

ahopkins commented 1 year ago

@niudinlp Two things:

First, this is not a bug, or at least I do not see you presenting us with one. This to me looks like a support request, which should be addressed to the proper channels if you would like our help.

A bug report should include a snippet of minimal, reproducible code so we can investigate.

Second, see GitHub for info on code formatting.