-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AIRFLOW-5417] Fix DB disconnects during webserver startup #6023
[AIRFLOW-5417] Fix DB disconnects during webserver startup #6023
Conversation
c896d8f
to
96e547c
Compare
Very interesting one. I read a bit about scoped session in this context. Just a thought: Maybe a better solution (still temporary but a bit less invasive) will be to run init_views in a separate thread and join it later (if we need to join it at all). This way the session will not be removed from the thread_local scope and in case it is used later on it might be still used? |
@potiuk thanks for reviewing and the idea. Actually I think the cost is actually less if we just remove the session. We have to recreate the connection but either way we'll have to use two connections to finish all the init steps. Removing a session from a scoped session is very safe but I'm not that sure about the safeness of parallelly initializing the app. |
Fair :). It's LGTM for me but maybe someone with more insight of Flask Can also take a look. |
TY! I'll keep it open for two more days then. |
[AIRFLOW-5417] Fix DB disconnects during webserver startup (apache#6023) (apache#306)
Make sure you have checked all steps below.
Jira
Description
The current workflow of creating an app in views.py is:
scoped_session
w/o a scope function, thus made the session a thread-local scope session, which will be reused until it is removed. Unfortunately flask-appbuilder doesn't remove the session after a query, e.g. 1.Problem with this is that if during step 3, there's a DB disconnect, step 4 will fail because the session is still attached with the disconnected DB connection and not rolled back. It becomes a bigger problem if step 3 regularly takes a long time, more than the DB connection expire time, step 4 will always fail, which is the case for us currently.
Tried to move the import of views.py to the outer scope but that seem to fail multiple tests. The approach here is to remove the session from the registry and the next session call will just create a new one automatically.
Of course the proper way is to fix the session usage in flask-appbuilder but that would be a longer term fix.
Tests
Not really changing the behavior.
Commits
Documentation