Repository: incubator-airflow Updated Branches: refs/heads/master ff45d8f22 -> 4905a5563
[AIRFLOW-191] Fix connection leak with PostgreSQL backend This issue happens because job falls asleep during heartbeat without closing a session, which holds a connection. This turns database connection into IDLE state, but doesn't releases it for other clients, so when connection poll get exhausted, they get blocked for ~heartbeat timeframe causing global performance degradation. Closes #1790 from kxepal/AIRFLOW-191-postgresql- connection-leak Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/4905a556 Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/4905a556 Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/4905a556 Branch: refs/heads/master Commit: 4905a5563d47b45e38b91661ee5aa7f3765a129b Parents: ff45d8f Author: Alexander Shorin <kxe...@apache.org> Authored: Mon Sep 19 15:44:32 2016 +0200 Committer: Bolke de Bruin <bo...@xs4all.nl> Committed: Mon Sep 19 15:44:39 2016 +0200 ---------------------------------------------------------------------- airflow/jobs.py | 4 ++++ 1 file changed, 4 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/4905a556/airflow/jobs.py ---------------------------------------------------------------------- diff --git a/airflow/jobs.py b/airflow/jobs.py index bae1168..d0e3c31 100644 --- a/airflow/jobs.py +++ b/airflow/jobs.py @@ -156,6 +156,9 @@ class BaseJob(Base, LoggingMixin): ''' session = settings.Session() job = session.query(BaseJob).filter_by(id=self.id).one() + make_transient(job) + session.commit() + session.close() if job.state == State.SHUTDOWN: self.kill() @@ -168,6 +171,7 @@ class BaseJob(Base, LoggingMixin): job.latest_heartbeat = datetime.now() + session = settings.Session() session.merge(job) session.commit()