Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscriptions are not always restored properly when reconnecting #273

Closed
DavidZidar opened this issue Aug 31, 2015 · 5 comments
Closed

Subscriptions are not always restored properly when reconnecting #273

DavidZidar opened this issue Aug 31, 2015 · 5 comments

Comments

@DavidZidar
Copy link

The internal class ConnectionMultiplexer.Subscription has logic that is supposed to ensure
that subscriptions are restored when reconnecting, however there seems to be a race condition
regarding in which order unsubscribe/subscribe commands are sent.

Sometimes the client resubscribes as expected but then, several seconds later, it may unsubscribe itself and thus forever be unsubscribed.

I find it a bit suspicious that the Validate-method sends unsubscribe and subscribe
commands using CommandFlags.FireAndForget. The order of these commands is very important but
is the order really preserved when using fire and forget?

Also, this may be unrelated, but it seems to me that there is a Dispose-call missing in PhysicalBridge.OnDisconnected around line 346. This strange unsubscribe-behaviour seems to completely disappear when I dispose the physical connection on disconnect.

@ghost
Copy link

ghost commented Sep 5, 2015

I'm observing the same issue using Amazon Redis (2.8) Elasticache. My client subscriptions never restore if I restart the Redis server. On disconnect I tried destroying the multiplexer and recreating & re-subscribing, but oddly that didn't help. Also tried your physical.dispose() suggestion - no help. Only thing that restores subscriptions is to restart my client application.

@andysinclair
Copy link

I'm experiencing the same issue; has anybody made any progress on working out why subscriptions are not restored on a reconnect?

@mail278
Copy link

mail278 commented Sep 23, 2016

I have the same problem and I can simulate it easily. Redis server disconnects slow clients (e.g. clients that overcome 8MB buffer limit). If send a lot of data in one application and pause receiving in other (I press pause in Visual Studio) I get disconnected and then reconnected but subscriptions are no longer valid.

Code 1: sender (flooder)

   using (var con = ConnectionMultiplexer.Connect("127.0.0.1"))
      {
        var data = File.ReadAllBytes(@"c:\bigfile"); // file should be cca 100kB large

        var sub = con.GetSubscriber();

        new Action(() =>
          {
            while (true)
            {

              sub.Publish("test", data, CommandFlags.FireAndForget);

              System.Threading.Thread.Sleep(1);
            }
          }).BeginInvoke(null, null);

        Console.ReadKey();
      }

Code 2: receiver

using (var con = ConnectionMultiplexer.Connect("127.0.0.1"))
      {
        var sub = con.GetSubscriber();

        sub.Subscribe("test", (c, v) =>
        {
          Console.WriteLine("Got notification: " + DateTime.Now);
        });

        // Pause VS now for about 10 seconds till server disconnects you, then unpause
        Console.ReadKey();
      }

@mail278
Copy link

mail278 commented Sep 23, 2016

Ok, strange thing - version 1.0.488 from the 5.november 2015 works fine (with my example). So this is probably different problem - still valid for last version though.

@NickCraver
Copy link
Collaborator

These issues were fixed in later versions of the lib, but I missed the duplicate issue - my fault. Just closing out to cleanup here, but the re-subscription logic is much more resilient now and we're no longer seeing reports of it in 1.2.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants