From 7a36c0133445f155f8af52b87eb05cb786fe501f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A4r=20Dahlman?= Date: Sun, 11 Mar 2018 12:46:22 +0100 Subject: [PATCH] (#303) Adding more logging in the channel pool --- src/RawRabbit/Channel/StaticChannelPool.cs | 59 +++++++++++++--------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/src/RawRabbit/Channel/StaticChannelPool.cs b/src/RawRabbit/Channel/StaticChannelPool.cs index 95e675ca..8d17bb83 100644 --- a/src/RawRabbit/Channel/StaticChannelPool.cs +++ b/src/RawRabbit/Channel/StaticChannelPool.cs @@ -46,36 +46,49 @@ private void StartServeChannels() if (!Monitor.TryEnter(_workLock)) { + _logger.Debug("Unable to aquire work lock for service channels."); return; } - _logger.Debug("Starting serving channels."); - do + try { - _current = _current?.Next ?? Pool.First; - if (_current == null) + _logger.Debug("Starting serving channels."); + do { - _logger.Debug("Unable to server channels. Pool empty."); - Monitor.Exit(_workLock); - return; - } - if (_current.Value.IsClosed) - { - Pool.Remove(_current); - if (Pool.Count != 0) continue; - Monitor.Exit(_workLock); - if (Recoverables.Count == 0) + _current = _current?.Next ?? Pool.First; + if (_current == null) { - throw new ChannelAvailabilityException("No open channels in pool and no recoverable channels"); + _logger.Debug("Unable to server channels. Pool empty."); + return; } - return; - } - if(ChannelRequestQueue.TryDequeue(out var cTsc)) - { - cTsc.TrySetResult(_current.Value); - } - } while (!ChannelRequestQueue.IsEmpty); - Monitor.Exit(_workLock); + if (_current.Value.IsClosed) + { + Pool.Remove(_current); + if (Pool.Count != 0) + { + continue; + } + if (Recoverables.Count == 0) + { + throw new ChannelAvailabilityException("No open channels in pool and no recoverable channels"); + } + _logger.Info("No open channels in pool, but {recoveryCount} waiting for recovery", Recoverables.Count); + return; + } + if (ChannelRequestQueue.TryDequeue(out var cTsc)) + { + cTsc.TrySetResult(_current.Value); + } + } while (!ChannelRequestQueue.IsEmpty); + } + catch (Exception e) + { + _logger.Info(e, "An unhandled exception occured when serving channels."); + } + finally + { + Monitor.Exit(_workLock); + } } protected virtual int GetActiveChannelCount()