Skip to content

Commit

Permalink
Merge pull request #38 from pardahlman/issue/#36
Browse files Browse the repository at this point in the history
Guard against KeyNotFound in dictionary
  • Loading branch information
pardahlman authored and pardahlman committed Feb 10, 2016
2 parents 8197371 + d49167c commit 278c519
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Pär Dahlman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 11 additions & 2 deletions src/RawRabbit/Operations/Requester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Task<TResponse> RequestAsync<TRequest, TResponse>(TRequest message, Guid
_logger.LogWarning($"Unable to find request timer for {props.CorrelationId}.");
}
timer?.Dispose();
responseTcs.TrySetException(new TimeoutException($"The request timed out after {_requestTimeout.ToString("g")}."));
responseTcs.TrySetException(new TimeoutException($"The request '{props.CorrelationId}' timed out after {_requestTimeout.ToString("g")}."));
}, null, _requestTimeout, new TimeSpan(-1)));

consumer.Model.BasicPublish(
Expand Down Expand Up @@ -143,7 +143,16 @@ private IRawConsumer GetOrCreateConsumerForType<TResponse>(IConsumerConfiguratio
{
var tcs = tcsAsObj as TaskCompletionSource<TResponse>;
_logger.LogDebug($"Recived response with correlationId {args.BasicProperties.CorrelationId}.");
_requestTimerDictionary[args.BasicProperties.CorrelationId]?.Dispose();

Timer timer;
if (_requestTimerDictionary.TryRemove(args.BasicProperties.CorrelationId, out timer))
{
timer?.Dispose();
}
else
{
_logger.LogInformation($"Unable to find request timer for message {args.BasicProperties.CorrelationId}.");
}
_errorStrategy.OnResponseRecievedAsync(args, tcs);
if (tcs?.Task?.IsFaulted ?? true)
{
Expand Down

0 comments on commit 278c519

Please sign in to comment.