Report this

What is the reason for this report?

Django Err_empty_response or connection reset

Posted on December 26, 2021

I have a django app and it is accessed via digital ocean auto generated ip address. I used to have this issue but it was not that often but today it was happening in every click. basically issue is when navigate to another link it gives me two types of errors. sometimes err_empty_response and sometime connection reset. most of the time the page gets auto reloaded and works fine. but real problem is when i have to submit the form. Basically i followed this tutorial to setup my server so you can assume that i have exactly same settings https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Heya,

The issue you’re experiencing with intermittent ERR_EMPTY_RESPONSE and “connection reset” errors in your Django application, especially when navigating to different links or submitting forms, can be caused by several factors. Given that you followed DigitalOcean’s tutorial for setting up Django with PostgreSQL, Nginx, and Gunicorn on Ubuntu 16.04, let’s consider some common causes and solutions:

1. Gunicorn Worker Timeout

Gunicorn workers might be timing out. This can happen if your Django views take too long to respond. To address this:

  • Increase Timeout: Increase the timeout value for Gunicorn workers in your Gunicorn configuration.
  • Increase Workers: If your server has enough resources, increasing the number of workers may help.

2. Nginx Configuration

Nginx might be improperly configured or might be facing timeout issues.

  • Check Nginx Error Logs: Look at the Nginx error logs (/var/log/nginx/error.log) for any specific error messages.
  • Increase Proxy Timeout: Increase the proxy_read_timeout and proxy_connect_timeout in your Nginx configuration.

3. Network Issues

Intermittent network issues between your server and the clients can cause these errors.

  • Check Server Load: High server load can cause network instability. Use commands like top, htop, or uptime to monitor server load.

4. Application Errors

There might be errors in your Django application causing it to respond inconsistently.

  • Check Django Logs: Look for errors in your Django application logs.
  • Debug Application: Use Django’s debugging tools to investigate the errors.

5. Database Connection Issues

Connection issues with PostgreSQL could also cause intermittent errors.

  • Check Database Logs: Look for any errors in your PostgreSQL logs.
  • Review Database Connections: Ensure that your database settings in Django (DATABASES configuration in settings.py) are correct and stable.

6. Server Resource Constraints

If your server is running low on resources (CPU, RAM), it can lead to various issues.

  • Monitor Server Resources: Use monitoring tools to check if your server is running low on resources.
  • Upgrade Server: If resource constraints are a regular issue, consider upgrading your server.

7. External Factors

External factors like DDoS attacks or issues with DigitalOcean’s network infrastructure can also cause such issues.

  • DigitalOcean Status: Check DigitalOcean’s status page for any ongoing issues.
  • Implement Security Measures: Ensure your server has adequate security measures against attacks.

Steps to Diagnose and Resolve

  1. Check Logs: Start by checking all relevant logs (Nginx, Gunicorn, Django, PostgreSQL).
  2. Monitor Server Performance: Look for any resource constraints or unusual activity on the server.
  3. Incremental Changes: Make incremental changes to configurations (Gunicorn, Nginx, Django) and monitor the impact.
  4. Reproduce Error: Try to consistently reproduce the error to better understand its cause.
  5. Consult Community Forums: If the issue persists, consider seeking advice on forums like DigitalOcean Community or Stack Overflow.

Always make sure to back up your configurations before making significant changes, and if possible, test these changes in a staging environment before applying them to production.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.