question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nginx + sanic problems

See original GitHub issue

Describe the bug

Hi, I’m using nginx as reverse-proxy to handle TLS and route to multiple applications on same server. My sanic app is the main route that handles most of the traffic. The traffic is pretty high (~5000 requests per second, on 16 workers) and I get some random errors in the nginx every few minutes. The errors are from these 3 types:

2022/08/18 12:05:20 [error] 42#42: *34037 writev() failed (32: Broken pipe) while sending request to upstream, client: 10.100.13.56, server: , request: "POST /engine HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "10.100.13.154"
2022/08/18 12:05:40 [error] 42#42: *35312 upstream prematurely closed connection while reading response header from upstream, client: 10.100.13.82, server: , request: "POST /engine HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "10.100.13.154"
2022/08/18 12:10:52 [error] 40#40: *55659 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.100.13.66, server: , request: "POST /engine HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "10.100.13.154"

On the sanic side there’s nothing in the logs. access_log=True and also debug=True didn’t show any error or anything suspicious, I also tried verbosity=5 but still nothing relevant.

Going deeper, I started tshark to try to see what actually happens, and I saw that the Sanic side actually sent tcp RST in the middle of a POST request being sent to it.

I tried setting SANIC_NOISY_EXCEPTIONS, increase SANIC_KEEP_ALIVE_TIMEOUT and REQUEST_BUFFER_SIZE - but still nothing helps.

I saw https://github.com/sanic-org/sanic/issues/991 which is quite old and has similar errors, but I’m using latest version and still have them.

Any idea what can cause it? Or how to fix it?

Environment (please complete the following information):

  • OS: Ubuntu 18.04
  • Sanic Version: 22.6.2 (Running inside docker using FROM python:3.8-slim-buster)
  • Docker version: 20.10.16, running containers with host network

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Troniccommented, Aug 23, 2022

There is an open issue (with a hacky workaround too) https://github.com/MagicStack/uvloop/issues/241

0reactions
ahopkinscommented, Aug 23, 2022

Nice find.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nginx Reverse Proxy + Sanic · Issue #991 - GitHub
I've setup a Nginx reverse proxy that forwards all HTTPS requests to an HTTP sanic backend using a private IP.
Read more >
Nginx Deployment — Sanic 20.9.1 documentation
We are setting the Sanic app to serve only locally at 127.0.0.1:8000 , while the Nginx installation is responsible for providing the service...
Read more >
NGINX vs Sanic | What are the differences? - StackShare
nginx and Sanic are both open source tools. Sanic with 12.4K GitHub stars and 1.16K forks on GitHub appears to be more popular...
Read more >
Performance Decline When Using Nginx Reverse Proxy
I'm just starting to learn Sanic framework because of its fast benchmark. I made a simple hello world API, then connected it with...
Read more >
Sanic: python web server that's written to die fast - Reddit
The problem is not specific to Sanic, consequences are relative ... for both Sanic and Reverse Proxy (like NGINX) is also very important....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found