sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.

Home Page:https://sanic.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

REQUEST_TIMEOUT & RESPONSE_TIMEOUT not working

Senhaji-Rhazi-Hamza opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I'm using sanic 23.12.1

I'm trying to use timeout feature to handle the time processing of the request, i'm using the exact same code presented
in the example :
https://github.com/sanic-org/sanic/blob/main/examples/request_timeout.py

It doesn't seems to work

Code snippet

import asyncio

from sanic import Sanic, response
from sanic.config import Config
from sanic.exceptions import RequestTimeout


Config.REQUEST_TIMEOUT = 1
app = Sanic("Example")


@app.route("/")
async def test(request):
    await asyncio.sleep(3)
    return response.text("Hello, world!")


@app.exception(RequestTimeout)
def timeout(request, exception):
    return response.text("RequestTimeout from error_handler.", 408)


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

Expected Behavior

The expected behaviour is to have RequestTimeout Exception raised

How do you run Sanic?

Sanic CLI

Operating System

Linux

Sanic Version

23.12.1

Additional context

By trying to understand what happening, in the checkt_timeouts function that is present under sanic/server/protocols/http_protocol.py, it seems that self._http.stage does'nt get updated to Stage.REQUEST or Stage.HANDLER, it always has the value Stage.IDLE