Make sure pach_all for gevent worker happens before everything else #27546
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change makes sure that gevent performs monkey_patching before everything else. Gevent should make sure to patch all the classes that are non-cooperative via gevent into cooperative ones and it should be done as the first thing in the forked gunicorn process.
Usually GeventWorker does it automatically, however this happens after the configuration of gunicorn gets imported. In our case it means that it happens after airflow setting are loaded - and for example it means that if S3 remote logging is configured, then boto is initialzed before patch_all() and it breaks ssl that is patched by boto itself. Reversing the sequence and making gevent patches the ssl connection first, fixes the problem.
We could convert airflow settings to local imports, but this does not guarantee a success because some of the initilization methods might be executed before GeventWorker starts and it is also prone to mistakes (adding top-level import to settings broke it at some point in time and it went unnoticed).
This change does it slightly differently - in case of gevent worker, we use a different configuration for gunicorn and make sure that patch_all() is always executed first before any other import and initialization. This should fix the problem and be future-proof.
Fixes: #8212
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rst
or{issue_number}.significant.rst
, in newsfragments.