Skip to content

Commit

Permalink
Added the channel name to exceptions to allow easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
kenkendk committed Feb 6, 2018
1 parent 1aa47f2 commit f4c2699
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/CoCoL.Network/NetworkClientConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private async Task RunClient(NetworkClient nwc)
case NetworkMessageType.RetiredResponse:
lock (m_lock)
m_pendingRequests[req.ChannelID].Remove(req.RequestID);
TrySetException(prq.Task, new RetiredException());
TrySetException(prq.Task, new RetiredException(req.AssociatedChannel?.Name));
break;
case NetworkMessageType.TimeoutResponse:
lock (m_lock)
Expand Down
24 changes: 12 additions & 12 deletions src/CoCoL/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public async Task<T> ReadAsync(TimeSpan timeout, ITwoPhaseOffer offer = null)
{
if (m_isRetired)
{
ThreadPool.QueueItem(() => rd.Source.SetException(new RetiredException()));
ThreadPool.QueueItem(() => rd.Source.SetException(new RetiredException(this.Name)));
return await rd.Source.Task;
}

Expand All @@ -446,15 +446,15 @@ public async Task<T> ReadAsync(TimeSpan timeout, ITwoPhaseOffer offer = null)
{
var exp = m_readerQueue[0].Source;
m_readerQueue.RemoveAt(0);
ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException()));
ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException(this.Name)));
}

break;
case QueueOverflowStrategy.LIFO:
{
var exp = m_readerQueue[m_readerQueue.Count - 2].Source;
m_readerQueue.RemoveAt(m_readerQueue.Count - 2);
ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException()));
ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException(this.Name)));
}

break;
Expand All @@ -463,7 +463,7 @@ public async Task<T> ReadAsync(TimeSpan timeout, ITwoPhaseOffer offer = null)
{
var exp = m_readerQueue[m_readerQueue.Count - 1].Source;
m_readerQueue.RemoveAt(m_readerQueue.Count - 1);
ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException()));
ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException(this.Name)));

await rd.Source.Task;
}
Expand Down Expand Up @@ -498,7 +498,7 @@ public async Task WriteAsync(T value, TimeSpan timeout, ITwoPhaseOffer offer = n
{
if (m_isRetired)
{
ThreadPool.QueueItem(() => wr.Source.SetException(new RetiredException()));
ThreadPool.QueueItem(() => wr.Source.SetException(new RetiredException(this.Name)));
await wr.Source.Task;
return;
}
Expand Down Expand Up @@ -544,7 +544,7 @@ public async Task WriteAsync(T value, TimeSpan timeout, ITwoPhaseOffer offer = n
var exp = m_writerQueue[m_bufferSize].Source;
m_writerQueue.RemoveAt(m_bufferSize);
if (exp != null)
ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException()));
ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException(this.Name)));
}

break;
Expand All @@ -553,7 +553,7 @@ public async Task WriteAsync(T value, TimeSpan timeout, ITwoPhaseOffer offer = n
var exp = m_writerQueue[m_writerQueue.Count - 2].Source;
m_writerQueue.RemoveAt(m_writerQueue.Count - 2);
if (exp != null)
ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException()));
ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException(this.Name)));
}

break;
Expand All @@ -563,7 +563,7 @@ public async Task WriteAsync(T value, TimeSpan timeout, ITwoPhaseOffer offer = n
var exp = m_writerQueue[m_writerQueue.Count - 1].Source;
m_writerQueue.RemoveAt(m_writerQueue.Count - 1);
if (exp != null)
ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException()));
ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException(this.Name)));
await wr.Source.Task;
}

Expand Down Expand Up @@ -692,7 +692,7 @@ private async Task RetireAsync(bool immediate, bool isLocked)
while (m_retireCount > 1)
{
if (m_writerQueue[0].Source != null)
m_writerQueue[0].Source.TrySetException(new RetiredException());
m_writerQueue[0].Source.TrySetException(new RetiredException(this.Name));
m_writerQueue.RemoveAt(0);
m_retireCount--;
}
Expand All @@ -712,7 +712,7 @@ public virtual async Task JoinAsync(bool asReader)
{
// Do not allow anyone to join after we retire the channel
if (m_isRetired)
throw new RetiredException();
throw new RetiredException(this.Name);

if (asReader)
m_joinedReaderCount++;
Expand Down Expand Up @@ -780,12 +780,12 @@ private async Task EmptyQueueIfRetiredAsync(bool isLocked)
{
if (readers != null)
foreach (var r in readers)
ThreadPool.QueueItem(() => r.Source.TrySetException(new RetiredException()));
ThreadPool.QueueItem(() => r.Source.TrySetException(new RetiredException(this.Name)));

if (writers != null)
foreach (var w in writers)
if (w.Source != null)
ThreadPool.QueueItem(() => w.Source.TrySetException(new RetiredException()));
ThreadPool.QueueItem(() => w.Source.TrySetException(new RetiredException(this.Name)));
}
}

Expand Down
28 changes: 22 additions & 6 deletions src/CoCoL/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,31 @@ namespace CoCoL
#endif
public class RetiredException : Exception
{
/// <summary>
/// The name of the channel that is retired
/// </summary>
public readonly string ChannelName;

/// <summary>
/// Initializes a new instance of the <see cref="CoCoL.RetiredException"/> class.
/// </summary>
public RetiredException() : base("The channel is retired") {}
/// <param name="channelname">The name of the channel</param>
public RetiredException(string channelname) : base($"The channel \"{channelname}\" is retired") { ChannelName = channelname; }

/// <summary>
/// Initializes a new instance of the <see cref="CoCoL.RetiredException"/> class.
/// </summary>
/// <param name="message">The error message.</param>
public RetiredException(string message) : base(message) {}
/// <param name="channelname">The name of the channel</param>
public RetiredException(string channelname, string message) : base(message) { ChannelName = channelname; }

/// <summary>
/// Initializes a new instance of the <see cref="CoCoL.RetiredException"/> class.
/// </summary>
/// <param name="message">The error message.</param>
/// <param name="ex">The inner exception.</param>
public RetiredException(string message, Exception ex) : base(message, ex) {}
/// <param name="channelname">The name of the channel</param>
public RetiredException(string channelname, string message, Exception ex) : base(message, ex) { ChannelName = channelname; }
#if !DISABLE_SERIALIZATION
/// <summary>
/// Initializes a new instance of the <see cref="CoCoL.RetiredException"/> class.
Expand All @@ -48,23 +56,31 @@ public class RetiredException : Exception
#endif
public class ChannelOverflowException : Exception
{
/// <summary>
/// The name of the channel that is overflown
/// </summary>
public readonly string ChannelName;

/// <summary>
/// Initializes a new instance of the <see cref="CoCoL.ChannelOverflowException"/> class.
/// </summary>
public ChannelOverflowException() : base("The channel has too many pending operations") {}
/// <param name="channelname">The name of the channel</param>
public ChannelOverflowException(string channelname) : base($"The channel \"{channelname}\" has too many pending operations") { ChannelName = channelname; }

/// <summary>
/// Initializes a new instance of the <see cref="CoCoL.ChannelOverflowException"/> class.
/// </summary>
/// <param name="message">The error message.</param>
public ChannelOverflowException(string message) : base(message) {}
/// <param name="channelname">The name of the channel</param>
public ChannelOverflowException(string message, string channelname) : base(message) { ChannelName = channelname; }

/// <summary>
/// Initializes a new instance of the <see cref="CoCoL.ChannelOverflowException"/> class.
/// </summary>
/// <param name="message">The error message.</param>
/// <param name="ex">The inner exception.</param>
public ChannelOverflowException(string message, Exception ex) : base(message, ex) {}
/// <param name="channelname">The name of the channel</param>
public ChannelOverflowException(string channelname, string message, Exception ex) : base(message, ex) { ChannelName = channelname; }
#if !DISABLE_SERIALIZATION
/// <summary>
/// Initializes a new instance of the <see cref="CoCoL.ChannelOverflowException"/> class.
Expand Down

0 comments on commit f4c2699

Please sign in to comment.