@@ -46,36 +46,49 @@ private void StartServeChannels()
4646
4747 if ( ! Monitor . TryEnter ( _workLock ) )
4848 {
49+ _logger . Debug ( "Unable to aquire work lock for service channels." ) ;
4950 return ;
5051 }
5152
52- _logger . Debug ( "Starting serving channels." ) ;
53- do
53+ try
5454 {
55- _current = _current ? . Next ?? Pool . First ;
56- if ( _current == null )
55+ _logger . Debug ( "Starting serving channels." ) ;
56+ do
5757 {
58- _logger . Debug ( "Unable to server channels. Pool empty." ) ;
59- Monitor . Exit ( _workLock ) ;
60- return ;
61- }
62- if ( _current . Value . IsClosed )
63- {
64- Pool . Remove ( _current ) ;
65- if ( Pool . Count != 0 ) continue ;
66- Monitor . Exit ( _workLock ) ;
67- if ( Recoverables . Count == 0 )
58+ _current = _current ? . Next ?? Pool . First ;
59+ if ( _current == null )
6860 {
69- throw new ChannelAvailabilityException ( "No open channels in pool and no recoverable channels" ) ;
61+ _logger . Debug ( "Unable to server channels. Pool empty." ) ;
62+ return ;
7063 }
71- return ;
72- }
73- if ( ChannelRequestQueue . TryDequeue ( out var cTsc ) )
74- {
75- cTsc . TrySetResult ( _current . Value ) ;
76- }
77- } while ( ! ChannelRequestQueue . IsEmpty ) ;
78- Monitor . Exit ( _workLock ) ;
64+ if ( _current . Value . IsClosed )
65+ {
66+ Pool . Remove ( _current ) ;
67+ if ( Pool . Count != 0 )
68+ {
69+ continue ;
70+ }
71+ if ( Recoverables . Count == 0 )
72+ {
73+ throw new ChannelAvailabilityException ( "No open channels in pool and no recoverable channels" ) ;
74+ }
75+ _logger . Info ( "No open channels in pool, but {recoveryCount} waiting for recovery" , Recoverables . Count ) ;
76+ return ;
77+ }
78+ if ( ChannelRequestQueue . TryDequeue ( out var cTsc ) )
79+ {
80+ cTsc . TrySetResult ( _current . Value ) ;
81+ }
82+ } while ( ! ChannelRequestQueue . IsEmpty ) ;
83+ }
84+ catch ( Exception e )
85+ {
86+ _logger . Info ( e , "An unhandled exception occured when serving channels." ) ;
87+ }
88+ finally
89+ {
90+ Monitor . Exit ( _workLock ) ;
91+ }
7992 }
8093
8194 protected virtual int GetActiveChannelCount ( )
0 commit comments