2

I'm using ServiceStack with the RedisServerEvents plugin to notify connected clients of changes in data. I've got two Linux VMs running Apache/mod_mono/ServiceStack, a single Redis instance, and an HAProxy machine in front.

Something I'm noticing is that, despite only currently having ~6 active users on daily testing the software (at least the portion that makes use of SSE), my Redis instance has thousands of keys starting with "sse:id...". All of them have a TTL of -1. I can clear all the keys out of the Redis instance, and the number of keys will slowly creep back up over time.

What I'm trying to figure out is: Is this expected behavior? Is there some action I need to be taking either on ServiceStack or my clients?

Paul R
  • 208,748
  • 37
  • 389
  • 560
SeanH
  • 584
  • 3
  • 18

1 Answers1

1

It should be removing the users subscription info when the subscription is removed. But when the AppDomain/Web App is shutdown it won't have cleaned up the existing subscriptions. I've just added a commit that will attempt to clean up any remaining active subscriptions whilst the AppDomain is shutting down, but it's possible if it wasn't shutdown cleanly there will be subscriptions remaining.

In which case you can call Reset() on Startup to clear out any previous subscriptions, e.g.

container.Register<IServerEvents>(c => 
    new RedisServerEvents(c.Resolve<IRedisClientsManager>()));

container.Resolve<IServerEvents>().Reset();

Note: this will need to be run before there are any active subscriptions on any servers otherwise it will remove them as well.

This change is available from v4.5.7 that's now available on MyGet.

mythz
  • 141,670
  • 29
  • 246
  • 390
  • Would it be reasonable to assume that any server events clients which believe they have a valid subscription will encounter an exception once Reset() is called? – SeanH Mar 08 '17 at 21:46
  • @SeanH Not when `Reset()` is called (which just silently removes state), the SSE Client will receive exceptions when it tries to send a heartbeat. – mythz Mar 08 '17 at 21:48
  • Sounds good... Easy enough to catch the ex and resubscribe / create a new SSE as needed, making updates during business hours painless ;-) – SeanH Mar 08 '17 at 21:55