Skip to content

Commit ea4e2d0

Browse files
update header across request session (#472)
Originally affirm reported log_event have this issue, but they also find out that dcs also has high failure over peer cancelled error See more context here statsig-io/private-python-sdk#469
1 parent b7e7e0e commit ea4e2d0

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

statsig/http_worker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def __init__(
5353
self.__temp_cert_files: List[str] = []
5454
self.__statsig_request_session = requests.Session()
5555
self.__request_session = requests.Session()
56+
self.__request_session.headers.update({
57+
"Connection": "close"
58+
})
5659

5760
def is_pull_worker(self) -> bool:
5861
return True
@@ -153,8 +156,7 @@ def log_events(
153156
) -> RequestResult:
154157
disable_compression = _SDK_Configs.on("stop_log_event_compression")
155158
additional_headers = {
156-
"STATSIG-RETRY": str(retry),
157-
"Connection": "close"
159+
"STATSIG-RETRY": str(retry)
158160
}
159161
if headers is not None:
160162
additional_headers.update(headers)

tests/test_network.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,8 @@ def test_invalid_post(self):
7373
},
7474
True,
7575
)
76+
77+
# Explicitly set Connection: close header to avoid peer connection issues in some environments
78+
def test_request_session_connection_header(self):
79+
request_session = self.net._HttpWorker__request_session
80+
self.assertEqual(request_session.headers.get("Connection"), "close")

0 commit comments

Comments
 (0)