Is it necessary to unsubscribe from StackExchange.Redis?

Viewed 265

I'm working on several Azure webjobs that use Redis for caching and for broadcasting messages. Each job runs continuously (as a console application) and may have several instances at any time (depending on scaling rules). When a job starts, it subscribes to a Redis channel to receive notifications:

...
var subscriber = multiplexer.GetSubscriber();

await (subscriber.SubscribeAsync("channel", HandleMessage));
...

private void HandleMessage(RedisChannel channel, RedisValue value)
{
    ...
}

We're using StackExchange.Redis 1.2.6.

My problem is that I cannot detect when an instance shuts down so I don't have a place where I can reliably call UnsubscribeAll() - nothing works that I tried so far:

  • AppDomain.Unload event
  • AppDomain.ProcessExit event
  • WebJobsShutdownWatcher

So far I've been only doing local testing on this. I'm not sure if I'm doing something wrong - there are many questions about detecting webjob shutdown - I (and all my coworkers) shut down local jobs by using Ctrl-C or clicking the X on the console window so the process just gets killed - no events are fired. Because of this, I cannot test any of my solutions locally. It doesn't feel right to let the process exit without cleaning up but I can't think of any other solution.

Is it necessary to unsubscribe from a Redis channel or is it safe to just forget about it? (Alternatively, would any of my above solutions work reliably in Azure?)

0 Answers
Related