SSLZeroReturnError problem in multithreaded gunicorn app

I have a python app hosted in APP engine with the gunicorn gthread worker: `gunicorn -w 4 --threads 16 src.main:app`

In my app i make requests to a GCP cloud function in this way:

`response = requests.post(url, json=payload)`

I have bugsnag as error reporting and i keep getting the following error:

`HTTPSConnectionPool(host='GCP CLOUD FUNCTION', port=443): Max retries exceeded with url: /path (Caused by SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:997)')))`

![Sample bugsnag error](https://user-images.githubusercontent.com/17838524/234068232-f9cce09d-9212-431c-bfe7-ab38a7e3bbee.png)


I'm using python 3.11 with requests 2.28.2 urllib3 1.26.15 How can i avoid this problem in a threaded gunicorn app?

At first i thought it was a problem with certificates, i tried setting `verify=False` in the requests.post call, and the error stopped, however the problem also occurs in other libraries i use, like bugsnag and google cloud storage (wich seem to use requests under the hood), and i can't disable that parameter there.

Maybe i was calling the function too much, i reduced calls per minute of my app, but it kept occurring.

Tried updating python and dependiencies, it also failed.

Then i tried a last approach, removing `--threads` from the gunicorn entrypoint, and then the error was gone.

Does python requests work in a multi threaded environment? I searched around and found it was, as long as i don't reuse a requests.Session in many threads, but that's not the case, unless... requests uses a global session under the hood?

> unless... requests uses a global session under the hood?

Nope. It doesn't.

> I'm using python 3.11 with requests 2.28.2 urllib3 1.26.15 How can i avoid this problem in a threaded gunicorn app?

Hard to say. I've never seen this problem in any gunicorn app. However, if you search the issue tracker there are lots of consistent issues on GAE. The way it meters HTTP causes odd errors for much of Python's networking stack.

> `SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:997)')`

This likely means that we started to establish the connection and then some intermediary (maybe  GAE) causes an issue by closing the socket. The foundational problem is something is closing the socket.

In all likelihood, you're opening too many sockets and GAE is rate-limiting you by closing the socket. That's not a bug in requests.

Unfortunately I am also having the same error. It happens in my Cloud Run, getting this error from one of the apis that I am using:
```
message: "Error occurred: HTTPSConnectionPool(host='google.serper.dev', port=443): Max retries exceeded with url: /search (Caused by SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1129)')))"
}
```
Here is my function for request:
```
def serper_search(self, arguments):
        query = arguments["q"]
        url = "https://google.serper.dev/search"
        payload = json.dumps({"q": query})
        headers = {
            'X-API-KEY': self.api_key,
            'Content-Type': 'application/json'
        }

        try:
            response = requests.request(
                "POST", url, headers=headers, data=payload)
            # Will raise an HTTPError if the HTTP request returned an unsuccessful status code
            response.raise_for_status()


            # Parse the response and make it ready 
            parsed_response = self.parse_response(response, number_of_results=3)
            return parsed_response  # Assuming the response content is in JSON format
        except requests.exceptions.HTTPError as http_err:
            logger.error(f"HTTP error occurred: {http_err}")
            return None
        except Exception as e:
            logger.error(f"Error occurred: {e}")
            return None
```
verify = False doesnt work.