Skip to content

Commit

Permalink
Dispose unused connection pool (apache#21565)
Browse files Browse the repository at this point in the history
  • Loading branch information
pingzh authored Feb 15, 2022
1 parent 7864693 commit 8155e8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions airflow/cli/commands/task_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ def task_run(args, dag=None):

settings.MASK_SECRETS_IN_LOGS = True

# IMPORTANT, have to use the NullPool, otherwise, each "run" command may leave
# IMPORTANT, have to re-configure ORM with the NullPool, otherwise, each "run" command may leave
# behind multiple open sleeping connections while heartbeating, which could
# easily exceed the database connection limit when
# processing hundreds of simultaneous tasks.
settings.configure_orm(disable_connection_pool=True)
settings.reconfigure_orm(disable_connection_pool=True)

if args.pickle:
print(f'Loading pickle id: {args.pickle}')
Expand Down
6 changes: 6 additions & 0 deletions airflow/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,12 @@ def dispose_orm():
engine = None


def reconfigure_orm(disable_connection_pool=False):
"""Properly close database connections and re-configure ORM"""
dispose_orm()
configure_orm(disable_connection_pool=disable_connection_pool)


def configure_adapters():
"""Register Adapters and DB Converters"""
from pendulum import DateTime as Pendulum
Expand Down

0 comments on commit 8155e8a

Please sign in to comment.