Commit 4576e34
committed
fix: make SetProviderAndWait behavior consistent with SetProvider
OpenFeature specification defines SetProviderAndWait as a waiting
version of SetProvider, or as a shortcut for waiting on provider ready
event. However, currently SetProvider and SetProviderAndWait exhibit
non-trivial behavior differences besides waiting.
SetProvider runs initialization asynchronously and potentially
concurrently with shutdown of the old provider. The API is not blocked
and the application author may initialize other providers
concurrently, run evaluations, etc.
🐛: in this mode, the error from initializer is ignored when updating
the provider state, so fatal/error states may be not set properly.
SetProviderAndWait runs initialization synchronously while holding
exclusive api.mu lock. This almost completely locks OpenFeature SDK:
the application author cannot initialize other providers (for
different domains), configure context or hooks, evaluate feature
flags, or shutdown SDK. If a provider initialization blocks
forever'ish, the SDK remains unusable and is unrecoverable.
Another difference is that old provider is shutdown only after new
provider has successfully initialized.
🐛: if the new provider fails to initialize, the old provider is
already unset in API but will never be shutdown, and the new provider
is not registered with api.eventExecutor (so if it comes back online
after some time, nobody listens to its events, and the state will go
out of sync if old provider continues emitting events).
🐛: in both modes, given that shutdown is run concurrently with
updating subscriptions in eventExecutor, it is possible for the old
provider to override the state of the new provider:
1. init finishes, emits provider ready event (directly from
goroutine), updates state
2. old provider emits some event during shutdown (e.g., PROVIDER_ERROR
or PROVIDER_STALE), eventExecutor receives the event and updates
the state to error/stale
3. new provider is registered with eventExecutor but the state is
already wrong.
This PR introduces a couple of changes:
Make initialization flow consistent across both modes: always
initialize async but make "AndWait" methods wait for initialization
outside of critical section. Make init respect returned error.
Always call shutdown on old provider (if it is no longer used).
Always register new provider with event executor. Do this before we
start init/shutdown, so the old provider cannot influence state of the
new provider. Make event executor registration non-erroring by making
shutdown channel buffered (there were no good way to recover from
registration error).
Signed-off-by: Oleksii Shmalko <oleksii.shmalko@datadoghq.com>1 parent 5b45d60 commit 4576e34
File tree
4 files changed
+117
-196
lines changed- openfeature
4 files changed
+117
-196
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | | - | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
| |||
192 | 190 | | |
193 | 191 | | |
194 | 192 | | |
195 | | - | |
| 193 | + | |
196 | 194 | | |
197 | 195 | | |
198 | 196 | | |
199 | 197 | | |
200 | 198 | | |
201 | 199 | | |
202 | 200 | | |
203 | | - | |
| 201 | + | |
204 | 202 | | |
205 | 203 | | |
206 | 204 | | |
207 | | - | |
| 205 | + | |
208 | 206 | | |
209 | 207 | | |
210 | 208 | | |
211 | 209 | | |
212 | 210 | | |
213 | 211 | | |
214 | 212 | | |
215 | | - | |
| 213 | + | |
216 | 214 | | |
217 | 215 | | |
218 | 216 | | |
219 | 217 | | |
220 | | - | |
| 218 | + | |
221 | 219 | | |
222 | 220 | | |
223 | 221 | | |
| |||
247 | 245 | | |
248 | 246 | | |
249 | 247 | | |
250 | | - | |
| 248 | + | |
251 | 249 | | |
252 | 250 | | |
253 | 251 | | |
| |||
258 | 256 | | |
259 | 257 | | |
260 | 258 | | |
261 | | - | |
| 259 | + | |
262 | 260 | | |
263 | 261 | | |
264 | 262 | | |
265 | 263 | | |
266 | 264 | | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
271 | 281 | | |
272 | 282 | | |
273 | 283 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 33 | + | |
37 | 34 | | |
38 | 35 | | |
39 | 36 | | |
40 | 37 | | |
41 | 38 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 39 | + | |
46 | 40 | | |
47 | 41 | | |
48 | 42 | | |
| |||
966 | 960 | | |
967 | 961 | | |
968 | 962 | | |
969 | | - | |
970 | 963 | | |
971 | 964 | | |
972 | 965 | | |
| |||
990 | 983 | | |
991 | 984 | | |
992 | 985 | | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
993 | 989 | | |
994 | 990 | | |
995 | 991 | | |
| |||
1009 | 1005 | | |
1010 | 1006 | | |
1011 | 1007 | | |
1012 | | - | |
1013 | 1008 | | |
1014 | 1009 | | |
1015 | 1010 | | |
| |||
1033 | 1028 | | |
1034 | 1029 | | |
1035 | 1030 | | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
1036 | 1034 | | |
1037 | 1035 | | |
1038 | 1036 | | |
| |||
1198 | 1196 | | |
1199 | 1197 | | |
1200 | 1198 | | |
1201 | | - | |
1202 | | - | |
1203 | | - | |
1204 | | - | |
| 1199 | + | |
1205 | 1200 | | |
1206 | 1201 | | |
1207 | 1202 | | |
1208 | 1203 | | |
1209 | 1204 | | |
1210 | 1205 | | |
1211 | | - | |
1212 | | - | |
1213 | | - | |
1214 | | - | |
| 1206 | + | |
1215 | 1207 | | |
1216 | | - | |
1217 | | - | |
1218 | | - | |
1219 | | - | |
| 1208 | + | |
1220 | 1209 | | |
1221 | 1210 | | |
1222 | 1211 | | |
| |||
1236 | 1225 | | |
1237 | 1226 | | |
1238 | 1227 | | |
1239 | | - | |
1240 | | - | |
1241 | | - | |
1242 | | - | |
| 1228 | + | |
1243 | 1229 | | |
1244 | | - | |
1245 | | - | |
1246 | | - | |
1247 | | - | |
| 1230 | + | |
1248 | 1231 | | |
1249 | 1232 | | |
1250 | 1233 | | |
| |||
1256 | 1239 | | |
1257 | 1240 | | |
1258 | 1241 | | |
1259 | | - | |
1260 | | - | |
1261 | | - | |
1262 | | - | |
| 1242 | + | |
1263 | 1243 | | |
1264 | 1244 | | |
1265 | 1245 | | |
| |||
1279 | 1259 | | |
1280 | 1260 | | |
1281 | 1261 | | |
1282 | | - | |
1283 | | - | |
1284 | | - | |
1285 | | - | |
| 1262 | + | |
1286 | 1263 | | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
1290 | | - | |
| 1264 | + | |
1291 | 1265 | | |
1292 | 1266 | | |
1293 | 1267 | | |
| |||
1299 | 1273 | | |
1300 | 1274 | | |
1301 | 1275 | | |
1302 | | - | |
1303 | | - | |
1304 | | - | |
1305 | | - | |
| 1276 | + | |
1306 | 1277 | | |
1307 | 1278 | | |
1308 | 1279 | | |
| |||
1322 | 1293 | | |
1323 | 1294 | | |
1324 | 1295 | | |
1325 | | - | |
1326 | | - | |
1327 | | - | |
1328 | | - | |
| 1296 | + | |
1329 | 1297 | | |
1330 | 1298 | | |
1331 | 1299 | | |
| |||
1337 | 1305 | | |
1338 | 1306 | | |
1339 | 1307 | | |
1340 | | - | |
1341 | | - | |
1342 | | - | |
1343 | | - | |
| 1308 | + | |
1344 | 1309 | | |
1345 | 1310 | | |
1346 | 1311 | | |
| |||
1560 | 1525 | | |
1561 | 1526 | | |
1562 | 1527 | | |
1563 | | - | |
1564 | | - | |
| 1528 | + | |
1565 | 1529 | | |
1566 | 1530 | | |
1567 | 1531 | | |
| |||
0 commit comments