@@ -77,8 +77,10 @@ public ValueTask<ServiceEndpointSource> GetEndpointsAsync(CancellationToken canc
77
77
async ValueTask < ServiceEndpointSource > GetEndpointsInternal ( CancellationToken cancellationToken )
78
78
{
79
79
ServiceEndpointSource ? result ;
80
+ var disposalToken = _disposalCancellation . Token ;
80
81
do
81
82
{
83
+ disposalToken . ThrowIfCancellationRequested ( ) ;
82
84
cancellationToken . ThrowIfCancellationRequested ( ) ;
83
85
await RefreshAsync ( force : false ) . WaitAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
84
86
result = _cachedEndpoints ;
@@ -194,7 +196,14 @@ private async Task RefreshAsyncInternal()
194
196
195
197
if ( OnEndpointsUpdated is { } callback )
196
198
{
197
- callback ( new ( newEndpoints , error ) ) ;
199
+ try
200
+ {
201
+ callback ( new ( newEndpoints , error ) ) ;
202
+ }
203
+ catch ( Exception exception )
204
+ {
205
+ _logger . LogError ( exception , "Error notifying observers of updated endpoints." ) ;
206
+ }
198
207
}
199
208
200
209
lock ( _lock )
@@ -244,10 +253,17 @@ private void SchedulePollingTimer()
244
253
/// <inheritdoc/>
245
254
public async ValueTask DisposeAsync ( )
246
255
{
247
- lock ( _lock )
256
+ try
248
257
{
249
258
_disposalCancellation . Cancel ( ) ;
259
+ }
260
+ catch ( Exception exception )
261
+ {
262
+ _logger . LogError ( exception , "Error cancelling disposal cancellation token." ) ;
263
+ }
250
264
265
+ lock ( _lock )
266
+ {
251
267
_changeTokenRegistration ? . Dispose ( ) ;
252
268
_changeTokenRegistration = null ;
253
269
0 commit comments