# Connection closed every couple of minutes

**URL:** https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309
**Category:** User
**Created:** [April 10, 2019, 1:38pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309 "2019-04-10T13:38:54Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![SamBull](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@SamBull](https://discuss.tryton.org/u/SamBull)
#### Post date: [April 10, 2019, 1:38pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/1 "2019-04-10T13:38:54Z")

</div>

I’ve just finished installing Tryton with the web interface. But, does anyone know why I keep getting this error every couple of minutes?

```
Traceback (most recent call last):
  File "/trytond/transactionpy", line 207, in commit
    self.connection.commit()
psycopg2InterfaceError: connection already closed

```

I’m running it under uWSGI via Nginx, if that’s relevant.

---

<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: [April 10, 2019, 1:59pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/2 "2019-04-10T13:59:28Z")

</div>

Is the DB server closing the connection every couple of minutes?

---

<div class="post-metadata">

### Author: ![SamBull](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@SamBull](https://discuss.tryton.org/u/SamBull)
#### Post date: [April 10, 2019, 2:03pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/3 "2019-04-10T14:03:17Z")

</div>

I’m not familiar with postgres configuration, what should I be looking for? It’s a default install in Debian buster, installed through the apt archives.

---

<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: [April 10, 2019, 2:22pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/4 "2019-04-10T14:22:39Z")

</div>

I would suspect a firewall between that cut stalling connection.

---

<div class="post-metadata">

### Author: ![SamBull](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@SamBull](https://discuss.tryton.org/u/SamBull)
#### Post date: [April 10, 2019, 2:26pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/5 "2019-04-10T14:26:37Z")

</div>

Tryton and postgres are running on the same machine, the only firewall rules I’m using block most of the external ports, there’s nothing time based.

---

<div class="post-metadata">

### Author: ![SamBull](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@SamBull](https://discuss.tryton.org/u/SamBull)
#### Post date: [April 10, 2019, 2:28pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/6 "2019-04-10T14:28:27Z")

</div>

And, the database connection is through a Unix socket:

`uri = postgresql://tryton:<PW>@/`

---

<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: [April 10, 2019, 2:28pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/7 "2019-04-10T14:28:35Z")

</div>

Well it may be the OS who close stalling TCP connection.

---

<div class="post-metadata">

### Author: ![SamBull](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@SamBull](https://discuss.tryton.org/u/SamBull)
#### Post date: [April 10, 2019, 2:34pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/8 "2019-04-10T14:34:23Z")

</div>

I also don’t seem to have any issues with other applications which are connecting to MariaDB and Redis servers over a Unix socket, so really not sure what’s going on here.

---

<div class="post-metadata">

### Author: ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)
#### Post date: [April 10, 2019, 3:16pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/9 "2019-04-10T15:16:07Z")

</div>

Same thing sometimes happens to me. But only when we (re)started Tryton-server and Nginx-server. I think it’s a configuration problem in Nginx, because at one client it is running fine, as at another client this happens. What I see on the client side is something about the bus. After login and logout about 2 - 3 times everything is back to normal and the message does not appear anymore.  
Because it appeared after restarting Tryton, it isn’t a issue at the moment so I didn’t dig deeper. But I think in my case it has something to do with the location definition in Nginx configuration.

---

<div class="post-metadata">

### Author: ![SamBull](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@SamBull](https://discuss.tryton.org/u/SamBull)
#### Post date: [April 10, 2019, 3:31pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/10 "2019-04-10T15:31:09Z")

</div>

Hmm, interesting. My server config is pretty basic, essentially if the file doesn’t exist, proxy to Tryton:

```
server {
	listen 443 ssl http2;
	listen [::]:443 ssl http2;

	server_name <domain>;
	root /var/www/tryton-sao/;

	<ssl_certs>

	more_set_headers "Content-Security-Policy: default-src 'none'; script-src 'self' 'unsafe-inline'; object-src 'none'; style-src 'self' 'unsafe-inline'; img-src 'self' blob:; media-src 'self'; frame-src 'none'; font-src 'self'; connect-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'; manifest-src 'none'; worker-src 'none'; upgrade-insecure-requests" always;

	location / {
		try_files $uri @tryton;
	}

	location @tryton {
		uwsgi_pass tryton;
		include uwsgi_params;
		uwsgi_request_buffering off;
	}

	location = /favicon.ico {
		alias /var/www/tryton-sao/images/tryton-icon.png;
	}

	location = /robots.txt {
		return 200 "User-agent: *\nDisallow: /\n";
	}
}

```

---

<div class="post-metadata">

### Author: ![SamBull](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@SamBull](https://discuss.tryton.org/u/SamBull)
#### Post date: [April 10, 2019, 3:37pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/11 "2019-04-10T15:37:18Z")

</div>

I tried logging in and out 3 times, but it also doesn’t seem to make a difference to me. If I open and close a few different tabs in the admin, I will encounter that error within a minute or 2.

It also sounds a bit weird that Nginx could be responsible for causing a connection between Tryton and the DB to get closed. Surely, that would be outside the control of Nginx.

---

<div class="post-metadata">

### Author: ![SamBull](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@SamBull](https://discuss.tryton.org/u/SamBull)
#### Post date: [April 10, 2019, 4:08pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/12 "2019-04-10T16:08:11Z")

</div>

Just to mention I’ve tried switching the DB connection to a localhost TCP connection, but get the same results either way.

---

<div class="post-metadata">

### Author: ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)
#### Post date: [April 10, 2019, 5:45pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/13 "2019-04-10T17:45:00Z")

</div>

Are you using the webclient? We are using the GTK desktop client. I’ve asked my client to pull the nginx.conf from the server. That one works for them.  
And from my memory there was a specific location with the databasename.

> ```
> location /production_database/ {
> uwsgi stuff
> }
> 
> ```

Can you can try something like that?

---

<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: [April 10, 2019, 6:08pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/14 "2019-04-10T18:08:40Z")

</div>

Another possibility is that the connection pool is started before the fork of µwsgi. In this case the connections could be shared between multiple process and closed by one while the other still use it.  
You could try to µwsgi option `lazy-apps=true` which prevent µwsgi to load the application before forking.

---

<div class="post-metadata">

### Author: ![SamBull](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@SamBull](https://discuss.tryton.org/u/SamBull)
#### Post date: [April 15, 2019, 3:39pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/15 "2019-04-15T15:39:34Z")

</div>

lazy-apps seems to have solved the issue, and I can even activate new modules in the admin now. 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: [April 15, 2019, 3:43pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/16 "2019-04-15T15:43:23Z")

</div>

How do you launch the µwsgi process? It will be good to understand why the connection pool is created before the fork (and see if we can fix that).

---

<div class="post-metadata">

### Author: ![SamBull](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@SamBull](https://discuss.tryton.org/u/SamBull)
#### Post date: [April 15, 2019, 4:11pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/17 "2019-04-15T16:11:35Z")

</div>

I run `service tryton-wsgi start`. Obviously, I had to configure all that myself as this is not something provided by the Debian package.

`/etc/systemd/system/tryton-wsgi.service`:

```
[Unit]
Description=Start uwsgi for Tryton ERP
After=network.target

[Service]
Type=simple
User=tryton
Group=www-data
PermissionsStartOnly=true
ExecStart=/usr/bin/uwsgi --post-buffering 65536 --ini /etc/tryton/uwsgi.ini

[Install]
WantedBy=multi-user.target

```

`/etc/tryton/uwsgi.ini`:

```
[uwsgi]
uid = tryton
gid = tryton
socket = /run/trytond/trytond.sock
chmod-socket = 660
plugins = python3
module = trytond.application:app
env = TRYTOND_CONFIG=/etc/tryton/trytond.conf
env = TRYTOND_LOGGING_CONFIG=/etc/tryton/trytond_log.conf
env = TRYTOND_DATABASE_NAMES=tryton

logto = /var/log/uwsgi/tryton.log
log-5xx = true
disable-logging = true

lazy-apps=true

master
workers = 1
max-requests = 200
harakiri = 30
die-on-term

```

---

<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: [April 15, 2019, 6:14pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/18 "2019-04-15T18:14:01Z")

</div>

> [@SamBull](#):
>
> env = TRYTOND\_DATABASE\_NAMES=tryton

This is the line that force the creation of the connection pool.  
I created [Do not copy connection pool after fork (#8281) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/issue8281) to be able to use the advantage of loading the database before the fork.

---

<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: [May 15, 2019, 6:14pm UTC](https://discuss.tryton.org/t/connection-closed-every-couple-of-minutes/1309/19 "2019-05-15T18:14:07Z")

</div>

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