Skip to content
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

Make sure pach_all for gevent worker happens before everything else #27546

Conversation

potiuk
Copy link
Member

@potiuk potiuk commented Nov 7, 2022

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.

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: apache#8212
@potiuk potiuk force-pushed the patch-non-cooperative-classes-in-gevent-case branch from 6c5e21f to fb119b0 Compare November 7, 2022 21:54
@potiuk potiuk marked this pull request as draft November 17, 2022 23:15
@potiuk
Copy link
Member Author

potiuk commented Dec 10, 2022

This was a dead-end

@potiuk potiuk closed this Dec 10, 2022
@potiuk potiuk deleted the patch-non-cooperative-classes-in-gevent-case branch April 4, 2023 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:CLI area:webserver Webserver related Issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't read S3 remote logs when using gevent/eventlent webserver workers.
1 participant