In this blog post I want to discuss a common issue that happens frequently when deploying a production Odoo instance. It is so frequent that I myself, having deployed numerous Odoo instances, sometimes forget to set correctly. For this reason I decided to write in this blog post two main reasons for the error "Connection lost... , Connection restored.."
There are two main reasons for this error: First setting the right number of worker counts in odoo.conf configuration file, and second setting the client_max_body_size in nginx configuration file to something larger than the default value of 1M.
Cause #1: Worker Woes
Odoo utilizes worker processes to handle requests efficiently. If you have insufficient workers configured, your system might struggle to keep up with incoming connections, leading to disconnects.
The Fix:
- Locate your odoo.conf file: This file typically resides in the /etc/ directory on Linux systems.
- Find the workers variable: Look for a line similar to workers = 1. The default value of 1 is often insufficient.
- Adjust the worker count: Here's the magic. Set the workers variable to a value that aligns with your server's resources and Odoo usage. A good starting point might be 2-4 workers for a basic setup, but you can adjust this based on your specific needs. It should be decided by the number of users your Odoo instance is serving and the number of CPUs of your server. You can find information about this here.
- Restart the Odoo service: Once you've modified the workers value, restart the Odoo service to apply the changes. The specific command for restarting the service can vary depending on your operating system. In Ubuntu it is sudo systemctl restart odoo.
Cause #2: Client_Max_Body_Size Blues
If you use nginx as a proxy server to run odoo behind it, the second reason for this error is because by default the value of client_max_body_size in nginx by default 1MB. This limitation can cause connection drops when data exceeds the allowed size, causing connection lost.., connection restored error.
The Fix:
- Locate your Nginx configuration file: This file is usually found in the /etc/nginx directory on Linux systems.
- Find the server block: Look for the section that defines how Nginx routes requests to your Odoo server.
- Adjust the client_max_body_size directive: Within the server block, locate the line containing client_max_body_size 1M;. Increase the value to accommodate your expected data size. A common recommendation is 10M or 20M, but adjust it based on your specific needs.
- Restart Nginx: Once you've modified the client_max_body_size, restart the Nginx service to apply the changes. The specific command for restarting Nginx can vary depending on your operating system. In Ubuntu it is sudo systemctl restart nginx. It is a good idea to restart Odoo server too.
Bonus Tip:
Always keep your Odoo instance and Nginx configuration up-to-date. New versions often include bug fixes and performance improvements that can help prevent connection issues.
By addressing these two potential causes, you can significantly reduce the chances of encountering the "Connection Lost, Reconnecting..." error. Remember, a well-configured Odoo environment translates to a smoother and more efficient user experience. Now go forth and conquer your Odoo tasks without interruptions!