Comments (10)
I believe the issue lies within the close() method. Instead of directly calling self.abort(), it should be replaced with:
timeout = self.app.config.GRACEFUL_SHUTDOWN_TIMEOUT
self.loop.call_later(timeout, self.abort)
By making this adjustment, the connection will function correctly. Otherwise, nginx encounters an error stating upstream prematurely closed connection while reading upstream.
from sanic.
@xbeastx Shouldn't this just be easily solvable by increasing the response timeout?
@ahopkins I just came across this issue upgrading from 23.6.0 to 23.12.1 and my response timeout is configured to 60 seconds which is not reached before response data is truncated, in my case always at 109kb, so to your question about increasing response_timeout, i don't think so.
There's also a thread on discord which seems to be the same issue https://discord.com/channels/812221182594121728/1209575840203939880
from sanic.
I can confirm this problem and this is a very critical bug.
from sanic.
I encountered the same issue. When utilizing the Python packages requests or aiohttp to send requests to a Sanic server, everything works fine. However, when using Nginx as a reverse proxy, Nginx reports an error: 'upstream prematurely closed connection while reading upstream.' Downgrading to sanic 23.6.0 resolves this error.
from sanic.
@ahopkins any chance you can confirm that the fix from @makeev all that is needed?
If so can we please do a point release for the 23.12 LTS branch?
from sanic.
I believe the issue lies within the close() method. Instead of directly calling self.abort(), it should be replaced with:
timeout = self.app.config.GRACEFUL_SHUTDOWN_TIMEOUT self.loop.call_later(timeout, self.abort)By making this adjustment, the connection will function correctly. Otherwise, nginx encounters an error stating upstream prematurely closed connection while reading upstream.
This code in sanic/server/protocol/http_protocol.py:242
appears to have been introduced in #2831. Ping @gluhar2006 can you have a look? This asyncio transport code is very complicated and easily broken by small details, also the docstring of that function is not quite understandable.
The graceful shutdown timeout normally has a different meaning in Sanic (roughly speaking: how long to wait for handler to finish), not that of just closing a TCP connection. Would need a bit deeper look at what exactly is being fixed here and what is to proper approach + write tests for those cases.
Possibly related also to #2531 (Nginx failures).
from sanic.
I believe the issue lies within the close() method. Instead of directly calling self.abort(), it should be replaced with:
timeout = self.app.config.GRACEFUL_SHUTDOWN_TIMEOUT self.loop.call_later(timeout, self.abort)By making this adjustment, the connection will function correctly. Otherwise, nginx encounters an error stating upstream prematurely closed connection while reading upstream.
This code in
sanic/server/protocol/http_protocol.py:242
appears to have been introduced in #2831. Ping @gluhar2006 can you have a look? This asyncio transport code is very complicated and easily broken by small details, also the docstring of that function is not quite understandable.The graceful shutdown timeout normally has a different meaning in Sanic (roughly speaking: how long to wait for handler to finish), not that of just closing a TCP connection. Would need a bit deeper look at what exactly is being fixed here and what is to proper approach + write tests for those cases.
Possibly related also to #2531 (Nginx failures).
It appears that the incorrect behavior of my changes was due to my misunderstanding of the meaning of the graceful shutdown timeout. I tried to look deeper, but so far without success. The main problem here is that I use Keep Alive 99% of the time, so I haven't encountered this problem when testing my changes.
I'll keep researching and come back if I find something.
As for now, I still cannot reproduce such problems with using keep-alive.
from sanic.
The graceful shutdown timeout normally has a different meaning in Sanic (roughly speaking: how long to wait for handler to finish), not that of just closing a TCP connection. Would need a bit deeper look at what exactly is being fixed here and what is to proper approach + write tests for those cases.
@Tronic I think they are just using the shutdown timer here as a further delay of the response timeout.
@ahopkins any chance you can confirm that the fix from @makeev all that is needed?
If so can we please do a point release for the 23.12 LTS branch?
@robd003 No. That is an incorrect use of graceful timeout. But also, I am not sure why we would want to further delay abort
. Needs investigation.
@xbeastx Shouldn't this just be easily solvable by increasing the response timeout?
from sanic.
Any work arounds for this problem?
from sanic.
Unfortunately I didn't find any explanation yet which would suit my understanding of this case. May be it's time to revert the changes
from sanic.
Related Issues (20)
- REQUEST_TIMEOUT & RESPONSE_TIMEOUT not working
- Documentation Hidden by Menu HOT 2
- Native Gzip & Brotli compression HOT 3
- AttributeError: 'Sanic' object has no attribute 'multiplexer' HOT 4
- help pls, when func A and func B are in defference Sanic-Server, same global asyncio.Event() var in them cant sync HOT 1
- TypeError: listener() got an unexpected keyword argument 'priority' HOT 3
- HTTPMethodView subclass to support generics HOT 1
- A question about request.json HOT 2
- Add sanic to crowdin
- How can a routing function not pass the request parameter HOT 1
- Throws an exception when I run with pycharm debug HOT 5
- sanic command line to start the app, developer mode -dev model error HOT 2
- Cors related traceback on `run_async.py` HOT 1
- RuntimeError: Event loop stopped before Future completed. HOT 2
- Middleware Runs Twice if Route Not Found + Middleware Exception HOT 8
- Blueprint.group and decorator HOT 3
- sanic 23 `FORWARDED_SECRET` forwarded VS x-headers HOT 8
- OpenAPI Documentation Issues for Class-Based Views Generating RESTful APIs HOT 2
- Signal handlers for SIGINT and SIGTERM are reset to SIG_IGN even when register_sys_signals is disabled HOT 2
- Official integration with Tortoise ORM occurring sync operations and errors HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sanic.