Skip to content

Commit 0d809f0

Browse files
authored
chore: Ensure transition to falling back state based on synchronizer failure. (#207)
Addresses the possible race condition raised in the previous initialization PR. <img width="772" height="350" alt="image" src="https://github.com/user-attachments/assets/464249fb-acc6-486d-bbfc-3ea3ddee1bdf" /> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Ensure InitializationTracker transitions to `FallingBack` when synchronizers turn `Off` with FDv1 fallback reason, and allow fallback from `NoData`. > > - **SDK Server (FDv2 InitializationTracker)**: > - When `DataSourceCategory.Synchronizers` report `Off` with `ErrorInfo.FDv1Fallback`, transition to `FallingBack`, then handle `SynchronizersExhausted`. > - Permit `Action.FallingBack` to transition `NoData` → `FallingBack`. > - For `FallbackSynchronizers` entering `Initializing`, also transition to `FallingBack`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 0fcbc78. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 3fa0a29 commit 0d809f0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkgs/sdk/server/src/Internal/FDv2DataSources/FDv2DataSource.InitializationTracker.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ private void DetermineState(Action action)
142142
case Action.DataReceived:
143143
_state = State.Data;
144144
break;
145+
case Action.FallingBack:
146+
_state = State.FallingBack;
147+
break;
145148
case Action.InitializersExhausted:
146149
_initializersRemain = false;
147150
_state = State.InitializersExhausted;
@@ -254,7 +257,16 @@ public void UpdateStatus(DataSourceState newState, DataSourceStatus.ErrorInfo? n
254257
}
255258
case DataSourceCategory.Synchronizers when newState == DataSourceState.Off:
256259
{
260+
// Currently, FDv1 fallback happens in the synchronizers group. If something from that group
261+
// reports Off, with a reason indicating that it should fallback to v1, then we can
262+
// transition to that state.
263+
if (newError.HasValue && newError.Value.FDv1Fallback)
264+
{
265+
DetermineState(Action.FallingBack);
266+
}
267+
257268
DetermineState(Action.SynchronizersExhausted);
269+
258270
break;
259271
}
260272
case DataSourceCategory.FallbackSynchronizers when newState == DataSourceState.Off:
@@ -264,6 +276,8 @@ public void UpdateStatus(DataSourceState newState, DataSourceStatus.ErrorInfo? n
264276
}
265277
case DataSourceCategory.FallbackSynchronizers when newState == DataSourceState.Initializing:
266278
{
279+
// In the normal flow this will have be already handled via the `Off` state of the
280+
// synchronizers. This is purely redundant in the current implementation.
267281
DetermineState(Action.FallingBack);
268282
break;
269283
}

0 commit comments

Comments
 (0)