Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
504 Gateway timeout

It is a known issue to many people even those who are not in the programming field. 504 timeout happens when a response for a request has taken longer than expected. There are times that you know and are sure that you need to increase this time. For example if users export a huge excel file as a report. In nginx you can increase this time to what seems to be appropriate from programmer point of view.

In nginx.conf usually in /etc/nginx/ do as follow:

proxy_connect_timeout       600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
send_timeout 600s;

More info: http://nginx.org/en/docs/http/ngx_http_proxy_module.html


#504 #gateway_timeout #timeout #nginx #proxy_read_timeout #proxy_send_timeout
Today I fixed a really C**Py bug which have been bugged me all days and years, nights and midnights!

I use a scheduler to to get data from MongoDB and one the servers is outside of Iran and another in Iran. When I want to get data sometimes querying the db takes forever and it freezes the data gathering procedure. I had to restart (like windows) to reset the connection. I know it was stupid! :|

I found the below parameter that you can set on your pymongo.MongoClient:

socketTimeoutMS=10000

socketTimeoutMS: (integer or None) Controls how long (in milliseconds) the driver will wait for a response after sending an ordinary (non-monitoring) database operation before concluding that a network error has occurred. Defaults to `None` (no timeout).
When you don't set it it means no timeout! So I set it to 20000 Ms (20 Sec) in order to solve this nasty problem.

#mongodb #mongo #socketTimeoutMS #timeout #socket_timeout
If for any reason you had to increase uwsgi_pass timeout in nginX you can use uwsgi_read_timeout:

upstream uwsgicluster {
server 127.0.0.1:5000;
}

.
.
.


include uwsgi_params;
uwsgi_pass uwsgicluster;
uwsgi_read_timeout 3000;


You can also increase timeout in uwsgi. If you are using ini file you need to use harakiri parameter like below:

harakiri = 30

Its value is in seconds.

#uwsgi #nginx #uwsgi_pass #harakiri #timeout #uwsgi_read_timeout