Skip to content

Commit 7818a16

Browse files
msfreedmitch-wilqo
andauthored
fix: protect callbacks against failures (#11)
Co-authored-by: Mitch Freed <[email protected]>
1 parent e604b74 commit 7818a16

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

Casbin.Watcher.Redis/Casbin.Watcher.Redis.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<ItemGroup>
2424
<PackageReference Include="Casbin.NET" Version="2.1.1" />
2525
<PackageReference Include="StackExchange.Redis" Version="2.7.17" />
26-
<PackageReference Include="System.Text.Json" Version="8.0.1" />
26+
<PackageReference Include="System.Text.Json" Version="8.0.1" Condition="'$(TargetFramework)'=='netstandard2.1'" />
2727
</ItemGroup>
2828

2929
<ItemGroup>

Casbin.Watcher.Redis/RedisWatcher.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,18 @@ private void Subscribe()
148148
var isSelf = message.Id == Id;
149149
if (!(isSelf && _options.IgnoreSelf))
150150
{
151-
if (_callbackWithMessage != null)
151+
try
152152
{
153-
_callbackWithMessage.Invoke(message);
154-
}
155-
else
156-
{
157-
_callback?.Invoke();
153+
if (_callbackWithMessage != null)
154+
{
155+
_callbackWithMessage.Invoke(message);
156+
}
157+
else
158+
{
159+
_callback?.Invoke();
160+
}
158161
}
162+
catch {}
159163
}
160164
});
161165
}
@@ -170,14 +174,18 @@ private void SubscribeAsync()
170174
var isSelf = message.Id == Id;
171175
if (!(isSelf && _options.IgnoreSelf))
172176
{
173-
if (_asyncCallbackWithMessage != null)
174-
{
175-
_asyncCallbackWithMessage.Invoke(message);
176-
}
177-
else
177+
try
178178
{
179-
_asyncCallback?.Invoke();
179+
if (_asyncCallbackWithMessage != null)
180+
{
181+
_asyncCallbackWithMessage.Invoke(message);
182+
}
183+
else
184+
{
185+
_asyncCallback?.Invoke();
186+
}
180187
}
188+
catch {}
181189
}
182190
});
183191
}

0 commit comments

Comments
 (0)