@@ -22,6 +22,7 @@ namespace LaunchDarkly.Sdk.Server.Internal.DataSources
2222 internal sealed class DataSourceUpdatesSanitizer : IDataSourceUpdates
2323 {
2424 private readonly IDataSourceUpdates _inner ;
25+ private readonly object _lock = new object ( ) ;
2526
2627 private bool _alreadyReportedInitializing ;
2728 private DataSourceState ? _lastState ;
@@ -53,35 +54,38 @@ public bool Upsert(DataKind kind, string key, ItemDescriptor item)
5354
5455 public void UpdateStatus ( DataSourceState newState , DataSourceStatus . ErrorInfo ? newError )
5556 {
56- var sanitized = newState ;
57-
58- // Map any future Off state to Interrupted
59- if ( sanitized == DataSourceState . Off )
57+ lock ( _lock )
6058 {
61- sanitized = DataSourceState . Interrupted ;
62- }
59+ var sanitized = newState ;
6360
64- // Don't report the same combination of values twice in a row.
65- if ( sanitized == _lastState && Nullable . Equals ( newError , _lastError ) )
66- {
67- return ;
68- }
61+ // Map any future Off state to Interrupted
62+ if ( sanitized == DataSourceState . Off )
63+ {
64+ sanitized = DataSourceState . Interrupted ;
65+ }
6966
70- if ( sanitized == DataSourceState . Initializing )
71- {
72- // Don't report initializing again if that has already been reported.
73- if ( _alreadyReportedInitializing )
67+ // Don't report the same combination of values twice in a row.
68+ if ( sanitized == _lastState && Nullable . Equals ( newError , _lastError ) )
7469 {
7570 return ;
7671 }
7772
78- _alreadyReportedInitializing = true ;
79- }
73+ if ( sanitized == DataSourceState . Initializing )
74+ {
75+ // Don't report initializing again if that has already been reported.
76+ if ( _alreadyReportedInitializing )
77+ {
78+ return ;
79+ }
8080
81- _lastState = sanitized ;
82- _lastError = newError ;
81+ _alreadyReportedInitializing = true ;
82+ }
83+
84+ _lastState = sanitized ;
85+ _lastError = newError ;
8386
84- _inner . UpdateStatus ( sanitized , newError ) ;
87+ _inner . UpdateStatus ( sanitized , newError ) ;
88+ }
8589 }
8690 }
8791}
0 commit comments