tcp: Re-use tcp sessions
Bug report
While investigating https://github.com/canonical/cloud-init/pull/5144, I realized that the code that is supposed to be re-using TCP session doesn't work correctly. The Session object gets re-used, however each individual call to readurl() ultimately creates a new session.
Session creation -> https://github.com/canonical/cloud-init/blob/120adcc1917a7e1157ad82615c202bf1a8d231fe/cloudinit/url_helper.py#L445
To reuse connections, we should create the session context outside of readurl().
Hi.
@holmanb datasourceScaleWay actually creates session before calling readurl. Just removing session from parameter to global can cause issues.
global_session = requests.Session()
What about to create global session object and use it if session object is None ?