sanic icon indicating copy to clipboard operation
sanic copied to clipboard

Allow RESPONSE_TIMEOUT to be disabled

Open GabrielCappelli opened this issue 2 years ago • 6 comments

Is your feature request related to a problem? Please describe. I would like to be able to disable RESPONSE_TIMEOUT so I can have long requests running until completion.

Describe the solution you'd like A common solution to disable timeouts is to set the value to 0.

Additional context N/A

GabrielCappelli avatar Jun 28 '22 14:06 GabrielCappelli

@Tronic and I have talked about an overhaul to timeouts. This is not going to land in the upcoming release, but is absolutely something I'm hoping to get into the end of Summer release.

ahopkins avatar Jun 28 '22 15:06 ahopkins

@GabrielCappelli Setting to float('inf') should do the trick.

Tronic avatar Jun 29 '22 10:06 Tronic

Zero to denote infinity is IMO a bad idea, even if many do it. I've seen inf used quite a bit for this on Python, but None could also work.

Tronic avatar Jun 29 '22 10:06 Tronic

Thanks for the responses. The float('inf') can do the trick for us with current implementation.

I think the only warning with using inf is that if you use it on all three timeouts (request, response and keep_alive) you'll schedule a call_later to inf, which I believe would leak some memory over time.

We're only interested in disabling the RESPONSE_TIMEOUT so it should be fine for our use case.

GabrielCappelli avatar Jun 29 '22 13:06 GabrielCappelli

I believe the timeout polling function is canceled at the end of the connection, but granted, it could be entirely avoided when there are no timeouts at all. However, the no timeout situation should also be quite rare as it makes it trivial to crash your server if you don't implement timeouts or other limits yourself or externally.

Tronic avatar Jun 30 '22 06:06 Tronic

Yeah, I've thought about this in the past about how we could implement per-endpoint overrides. The difficulty is that the timers live outside of routing.

ahopkins avatar Jun 30 '22 11:06 ahopkins