heroku: all background tasks end with database errors
<p>I have several background Django tasks on my Heroku project. When they are run, each task causes an error log by postgres:</p>

<pre><code>2016-02-17T20:08:21Z app[postgres.889]: [DATABASE] could not receive data from client: Connection reset by peer
</code></pre>

<p>this happens even with tasks that only read the DB, not even write anything.</p>

<p>Heroku's help pages say:</p>

<blockquote>
  <p>Postgres noticed that the client (your application) disappeared without ending the connection properly, and logged a message saying so.</p>
</blockquote>

<p>but my tasks don't have errors.</p>

<p>for example take this task:</p>

<pre><code># -*- coding: utf-8 -*-
"""
just a test task
"""
from __future__ import division, absolute_import, unicode_literals
import os

import django

os.environ['DJANGO_SETTINGS_MODULE'] = 'django_cpa.settings'
django.setup()

from pubscout.models import Campaign


def main():
    active_campaigns = Campaign.objects.filter(active=True).all()
    print(active_campaigns)

if __name__ == '__main__':
    main()
</code></pre>

<p>it ends without error, printing what's requested, but heroku logs say:</p>

<pre><code>2016-02-17T20:15:42.998688+00:00 heroku[run.4686]: Starting process with command `python _scheduled/_test_task.py`
2016-02-17T20:15:43.281803+00:00 heroku[run.4686]: State changed from starting to up
2016-02-17T20:15:45Z app[postgres.1001]: [DATABASE] could not receive data from client: Connection reset by peer
2016-02-17T20:15:46.739799+00:00 heroku[run.4686]: State changed from up to complete
2016-02-17T20:15:46.715022+00:00 heroku[run.4686]: Process exited with status 0
</code></pre>

<p>what's wrong?</p>