Skip to content

Commit 334394b

Browse files
authored
update automatic retries to include read errors (#208)
in e.g. lambda environments the connection can time out between invocations, this comes through to the client as a "RemoteDisconnected" error, which it turns out urllib classifies as a "read" error not a connection error (as it's possible to get this error after data has been sent)
1 parent 14a2f80 commit 334394b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.23.0 – 2025-03-26
2+
3+
1. Expand automatic retries to include read errors (e.g. RemoteDisconnected)
4+
15
## 3.22.0 – 2025-03-26
26

37
1. Add more information to `$feature_flag_called` events.

posthog/request.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@
77

88
import requests
99
from dateutil.tz import tzutc
10+
from urllib3.util.retry import Retry
1011

1112
from posthog.utils import remove_trailing_slash
1213
from posthog.version import VERSION
1314

14-
adapter = requests.adapters.HTTPAdapter(max_retries=2)
15+
# Retry on both connect and read errors
16+
# by default read errors will only retry idempotent HTTP methods (so not POST)
17+
adapter = requests.adapters.HTTPAdapter(
18+
max_retries=Retry(
19+
total=2,
20+
connect=2,
21+
read=2,
22+
)
23+
)
1524
_session = requests.sessions.Session()
1625
_session.mount("https://", adapter)
1726

0 commit comments

Comments
 (0)