pardahlman / RawRabbit

A modern .NET framework for communication over RabbitMq
MIT License
747 stars 144 forks source link

An unhandled exception was thrown when consuming a message #204

Closed PeterKottas closed 7 years ago

PeterKottas commented 7 years ago

Hi mate, hope you are well. I've been using this lib for a while and only recently have I started seeing these mysterious exceptions. I'll try to provide more info if needed but I was wondering it might ring a bell just seeing this

RawRabbit.Exceptions.MessageHandlerException: An unhandled exception was thrown when consuming a message
  MessageId: 7dd03f55-e47c-4908-9e10-e4c165dc4007
  Queue: 'myQueueName'
  Exchange: 'myExchangeName'
See inner exception for more details.
   at RawRabbit.Operations.Requester`1.<>c__15`2.<SendRequestAsync>b__15_2(Task`1 tResponse)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at TotepoolLiveInfoVNext.Proxies.FeedParser.FeedParserProxy.<Racecard>d__4.MoveNext() in D:\TeamCity\buildAgent\work\e7af9657aed0a746\Source\Proxies\Proxies.FeedParser\FeedParserProxy.cs:line 52

The code isn't anything special, it looks like this and the exception is thrown and catched here:

        public async Task<RacecardResponseDTO> Racecard(RacecardRequestDTO request)
        {
            logger.Info(() => $"Starting {typeof(FeedParserProxy).FullName}.{nameof(Racecard)}...", request);
            try
            {
                return await client.RequestAsync<RacecardRequestDTO, RacecardResponseDTO>(request);
            }
            catch (Exception e)
            {
                logger.Error(() => $"Exception calling {typeof(FeedParserProxy).FullName}.{nameof(Racecard)}...", request, e);
                var resp = request.GetResponse<RacecardResponseDTO>(initResp =>
                {
                    initResp.Status = OperationStatusEnum.Failure;
                    return initResp;
                });
                return resp;
            }
            finally
            {
                logger.Info(() => $"Finished {typeof(FeedParserProxy).FullName}.{nameof(Racecard)}.", request);
            }
        }

Line 52 mentioned in the exception is the one where I call the client. Version of your lib is 1.10.3, the client is a wrapper that basically just call your client directly.

I'll continue looking into it but it might be a banality that can catch other people so I figured it's best to ask the author ;)

PeterKottas commented 7 years ago

As a side note, is raw rabbit thread safe? Cause this method in fact can be called from different threads.

PeterKottas commented 7 years ago

I think I found the problem. It appears I might have been referencing different versions of my DTOs across different services. I am doing some more tests but as long as it goes well, I'll probably close this within next few days.

pardahlman commented 7 years ago

Hello @PeterKottas - all well 👌 ! Sounds like you might have found the source of the problem. I'll wait to hear back from you before further investigation. Version 1.10.3 has been around for a while, so my gut feeling is that it just might be related to other changes in your application 🙂.

RawRabbit is theadsafe and we're regularly use it for batch work with hundreds concurrent operations.

Have a great evening!

PeterKottas commented 7 years ago

Glad to hear that. Yep it was version missmatch. One of the services connecting to rabbit had old version of binaries. That was it. Deserialization then obviously didn't work. It's quite reassuring to hear that raw rabbit is thread safe, I was almost sure of it but it never hurts to double check :) Carry on with the good work and thanks for the help.