hterik opened a new issue, #37484:
URL: https://github.com/apache/airflow/issues/37484

   ### Apache Airflow version
   
   2.8.1
   
   ### If "Other Airflow 2 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   After observing `_airflow_parsing_context_manager` in 
`airflow/utils/dag_parsing_context.py` i can see that it is modifying the 
`os.environ` when entering the context manager.
   Writing to `os.environ` is generally a bad idea, because lower level 
`getenv/setenv` functions are not thread safe. Meaning that, unless you have 
100% control over that no other threads have been spawned yet, the only way to 
ensure thread safety is to never write to environment  [1]
   In the context where this code is executing, i believe this is very hard to 
guarantee.
   
   From what i can tell, these envvars are never used outside of this python 
module, so i believe there is no need for these to be environment variables. 
Unless there is an expectation of it being passed through several airflow 
invocations.
   If that is the case, the solution in this case is simple, instead of using 
environment variables, one can use Pythons `contextlib.ContextVar`. 
   Plain global python variables here would also work equally good.
   
   [1]  https://news.ycombinator.com/item?id=37908655 
   
   
   ### What you think should happen instead?
   
   _No response_
   
   ### How to reproduce
   
   See above
   
   ### Operating System
   
   NA
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Other
   
   ### Deployment details
   
   _No response_
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to