File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
ProReception.DistributionServerInfrastructure/HostedServices Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,15 @@ public Task StartAsync(CancellationToken cancellationToken)
3535 {
3636 startUpTask = ExecuteStartUp ( stoppingCts . Token ) ;
3737
38+ // Observe exceptions from the background task to prevent unobserved task exceptions from crashing the service
39+ _ = startUpTask . ContinueWith ( task =>
40+ {
41+ if ( task . IsFaulted && task . Exception != null )
42+ {
43+ logger . LogError ( task . Exception , "Fatal error in {ServiceName} startup - service may be in degraded state" , typeof ( T ) . Name ) ;
44+ }
45+ } , TaskScheduler . Default ) ;
46+
3847 return Task . CompletedTask ;
3948 }
4049
@@ -124,11 +133,13 @@ private async Task LoginAndCreateSignalRConnection(CancellationToken cancellatio
124133 }
125134 catch ( Exception ex )
126135 {
127- logger . LogWarning ( ex , "SignalR AccessTokenProvider: failed to refresh token" ) ;
128- // Return existing token (may fail with 401 and trigger reconnect), or null if missing
136+ logger . LogError ( ex , "SignalR AccessTokenProvider: CRITICAL - failed to refresh token, using existing token" ) ;
137+ // Return existing token (may fail with 401 and trigger reconnect)
138+ // Don't throw - let SignalR handle the authentication failure and reconnect
129139 if ( string . IsNullOrWhiteSpace ( current . AccessToken ) )
130140 {
131- return null ;
141+ logger . LogError ( "SignalR AccessTokenProvider: No valid token available, returning empty string" ) ;
142+ return string . Empty ;
132143 }
133144 }
134145 }
You can’t perform that action at this time.
0 commit comments