pardahlman / RawRabbit

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

Fixing : Get request on empty queue throws a null exception #326

Closed Ankurkh1 closed 6 years ago

Ankurkh1 commented 6 years ago

Description

Fixing : Get request on empty queue throws a null exception fix #323

Fixing : Get Operation causing "ChannelAllocationException: The connection cannot support any more channels. Consider creating a new connection"

fix #325

Check List

pardahlman commented 6 years ago

Thanks @Ankurkh1 - I'll give this a closer look in a few days! 👏

pardahlman commented 6 years ago

Excellent work! Thanks @Ankurkh1 👌

pardahlman commented 6 years ago

Ah @Ankurkh1 - it just dawned on my why this operation didn't use the channel pool: The channel is closed as the consumer disposes the Ackable<TMessage> like so

using(var ackable = await client.GetManyAsync<BasicMessage>(3))
{
  foreach (var message in ackable.Content)
  {
    if (TryDoWork(message))
    {
      message.Ack();
    }
    else
    {
      message.Nack();
    }
  }
}

(You could also dispose the ackable explicitly ackable.Dispose(). It feels a bit dangerous to close channels in the default channel pool as the ackable is GC'ed, so I'll revert the fix so that the method creates its own channels. I believe that the problems you had could be eliminated by following the pattern above.

Ankurkh1 commented 6 years ago

Thanks for the Reply @pardahlman. I tried what you have suggested here and I am sorry to report, the problem still persist. I am using message.Dispose() and a later stage and in watch window I can see the channel marked as closed with reply test "Good bye" but, on server side the channel count on the connection reached 65535. I am not savvy enough with RabbitMQ to know what is going on. Is it a requirement to call explicit close on the channel?

Like always, any help would be greatly appreciated!!