Long-running local git operations and Redmine API calls can cause the idle
keep-alive connection to api.github.com to be closed by the remote server.
When the script later attempts to post automated PR comments, it fails with
http.client.RemoteDisconnected.
Fix this by mounting an urllib3 Retry adapter to the requests.Session,
automatically re-establishing dropped connections up to 3 times on
transient network or server errors (500, 502, 503, 504).
Assisted-by: Gemini
Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
try:
import requests
+ from requests.adapters import HTTPAdapter
+ from urllib3.util.retry import Retry
except ImportError:
MISSING_DEPS.append("requests")
merge_branch_name = args.merge_branch_name
session = requests.Session()
+ retries = Retry(
+ total=3,
+ backoff_factor=1,
+ status_forcelist=[500, 502, 503, 504],
+ raise_on_status=False
+ )
+ session.mount("https://", HTTPAdapter(max_retries=retries))
+ session.mount("http://", HTTPAdapter(max_retries=retries))
if label:
# Check the label format