Repository navigation
Commit 6d8aef0
committed
feat: feature refresh listeners on both clients
Applications had no supported way to react to a feature payload being applied.
The plumbing existed but wasn't reachable: the sync path exposed it only on the
module-level feature_repo singleton, and the async path only through
client._features_repository, a private attribute, with an async-only callback.
Adds add_feature_refresh_listener / remove_feature_refresh_listener to both
GrowthBook and GrowthBookClient. The add method returns a callable that
unregisters the listener. Listeners receive the raw payload dict and run after
it has been applied, so evaluating from inside a listener already sees the new
definitions. A listener that raises is logged and skipped. The async client
accepts plain functions and coroutine functions alike.
Also fixes a gap on the way: the sync streaming path applied payloads and wrote
the cache without notifying anything, so in SSE mode — the case this feature
exists for — nothing observed the update.
Three ordering and lifecycle details, each with a regression test:
Dispatch is keyed on payload identity, so listeners fire once per refresh
rather than once per evaluation (evaluation calls load_features() constantly
and usually gets a cache hit, which returns the same object).
A failed refresh no longer clears that identity marker. It applies nothing, so
the payload listeners last saw is unchanged; clearing it made the next cache
hit — which returns that same previously-notified object — look fresh and fire
listeners a second time.
Apply and notify happen as one unit. In the sync client that is the reentrant
payload-writer lock, which evaluation never takes. In the async client it is a
separate ordering lock, since evaluation takes the context lock and notifying
under that one deadlocks any listener that evaluates. Without this, two
overlapping refreshes could apply A, apply and notify B, then notify A —
handing listeners an older payload last and letting a listener see state that
doesn't match the payload it was given.
GrowthBookClient.close() clears the listener list, matching subscriptions and
the sync client. Listener closures capture application objects, and a
reinitialized client would otherwise fire callbacks from its previous
lifecycle.1 parent 962ca8f commit 6d8aef0
5 files changed
Lines changed: 474 additions & 5 deletions
File tree
- growthbook
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
292 | 327 | | |
293 | 328 | | |
294 | 329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1005 | 1005 | | |
1006 | 1006 | | |
1007 | 1007 | | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
1008 | 1014 | | |
1009 | 1015 | | |
1010 | 1016 | | |
| |||
1083 | 1089 | | |
1084 | 1090 | | |
1085 | 1091 | | |
1086 | | - | |
1087 | | - | |
| 1092 | + | |
1088 | 1093 | | |
1089 | 1094 | | |
1090 | 1095 | | |
| |||
1150 | 1155 | | |
1151 | 1156 | | |
1152 | 1157 | | |
1153 | | - | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
1154 | 1164 | | |
1155 | 1165 | | |
1156 | 1166 | | |
| |||
1169 | 1179 | | |
1170 | 1180 | | |
1171 | 1181 | | |
1172 | | - | |
| 1182 | + | |
1173 | 1183 | | |
1174 | 1184 | | |
1175 | 1185 | | |
| |||
1180 | 1190 | | |
1181 | 1191 | | |
1182 | 1192 | | |
1183 | | - | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
1184 | 1197 | | |
1185 | 1198 | | |
1186 | 1199 | | |
| |||
1255 | 1268 | | |
1256 | 1269 | | |
1257 | 1270 | | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
1258 | 1337 | | |
1259 | 1338 | | |
1260 | 1339 | | |
| |||
1340 | 1419 | | |
1341 | 1420 | | |
1342 | 1421 | | |
| 1422 | + | |
1343 | 1423 | | |
1344 | 1424 | | |
1345 | 1425 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
657 | 657 | | |
658 | 658 | | |
659 | 659 | | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
660 | 667 | | |
661 | 668 | | |
662 | 669 | | |
| |||
810 | 817 | | |
811 | 818 | | |
812 | 819 | | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
813 | 868 | | |
814 | 869 | | |
815 | 870 | | |
| |||
1185 | 1240 | | |
1186 | 1241 | | |
1187 | 1242 | | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
1188 | 1255 | | |
1189 | 1256 | | |
1190 | 1257 | | |
| |||
1443 | 1510 | | |
1444 | 1511 | | |
1445 | 1512 | | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
1446 | 1518 | | |
1447 | 1519 | | |
1448 | 1520 | | |
| |||
0 commit comments