# 502 Bad Gateway when running Stock Quantity Issues wizard

**URL:** <https://discuss.tryton.org/t/502-bad-gateway-when-running-stock-quantity-issues-wizard/8107>\
**Category:** Developer\
**Tags:** tryton\
**Created:** [December 9, 2024, 10:59am UTC](https://discuss.tryton.org/t/502-bad-gateway-when-running-stock-quantity-issues-wizard/8107 "2024-12-09T10:59:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)\
**Post date:** [December 9, 2024, 10:59am UTC](https://discuss.tryton.org/t/502-bad-gateway-when-running-stock-quantity-issues-wizard/8107/1 "2024-12-09T10:59:38Z")

</div>

Hi,

When launching long time process such “Generate Stock Quantity Issues” wizard, I get “502 Bad Gateway” error after some time. (Nginx error log: “upstream prematurely closed connection while reading response header from upstream”)

My server is launched with gunicorn behind nginx.

Here’s my nginx configuration:

```auto
server {
    listen 8000;
    server_name trytond-server;
    client_max_body_size 100M;

    location / {
        proxy_pass http://unix:/srv/tryton/7.2/trytond.sock;
        proxy_read_timeout 600s;
        proxy_connect_timeout 75s;
    }
}

```

and my gunicorn configuration:

```auto
wsgi_app = 'trytond.application:app'
bind = 'unix:/srv/tryton/7.2/trytond.sock'
workers = 5
worker_class = 'gevent'
worker_connections = 1000
timeout = 600
raw_env = [
        'TRYTOND_CONFIG=/srv/tryton/7.2/trytond.conf',
        'TRYTOND_DATABASE_NAMES = tryton_preciball_prod_72',
        'TRYTOND_LOGGING_CONFIG=/srv/tryton/7.2/trytond_log.conf',
]
PYTHONOPTIMIZE = 1

```

Any advice to avoid such error ? Thanks. 🙂

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [December 9, 2024, 11:16am UTC](https://discuss.tryton.org/t/502-bad-gateway-when-running-stock-quantity-issues-wizard/8107/2 "2024-12-09T11:16:38Z")

</div>

You probably need to increase the `proxy_read_timeout`.  
I wrote [Retries on gateway timeout (#13222) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/13222) to make it work transparently.

---

<div class="post-metadata">

**Author:** ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)\
**Post date:** [December 9, 2024, 12:09pm UTC](https://discuss.tryton.org/t/502-bad-gateway-when-running-stock-quantity-issues-wizard/8107/3 "2024-12-09T12:09:15Z")

</div>

It’s working now 🙂

I forgot to restart gunicorn after my changes.

My configuration files in the initial post are correct.  
So, I’ve increased gunicorn _timeout_ from 90 to 600 and added _proxy\_read\_timeout_ and _proxy\_connect\_timeout_ to nginx configuration to avoid 502 error.

---

<div class="post-metadata">

**Author:** ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)\
**Post date:** [December 10, 2024, 12:09pm UTC](https://discuss.tryton.org/t/502-bad-gateway-when-running-stock-quantity-issues-wizard/8107/4 "2024-12-10T12:09:42Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
