calling connection.Stop() in a callback causes a deadlock on the client side #2535

Closed
jcondex opened this Issue Sep 7, 2013 · 1 comment

Projects

None yet

3 participants

@jcondex

In the C# client, calling connection.Stop inside a hubProxy callback causes the call to Stop() to hang for several seconds.

Here is the repro.

Client:

        public static void HubIsSending()
        {
            int i = 0;
            while (!Console.KeyAvailable)
            {
                Console.WriteLine("[{0}] New iteration ...", i++);
                using (ManualResetEvent mre = new ManualResetEvent(false))
                {
                    HubConnection connection = new HubConnection("http://localhost/Server");

                    IHubProxy hubProxy = connection.CreateHubProxy("EchoHub");

                    hubProxy.On(
                        "ReadyToSend",
                        () =>
                        {
                            connection.Stop();
                            mre.Set();
                        });


                    hubProxy.On<string>(
                        "ReceivePayload",
                        (p) =>
                        {
                            Console.WriteLine(connection.State);
                        });

                    //connection.Start(new WebSocketTransport()).Wait();
                    connection.Start(new ServerSentEventsTransport()).Wait();

                    hubProxy.Invoke("SendPayload");

                    mre.WaitOne();
                }
            }
        }

Hub:

        public void SendPayload()
        {
            Clients.Caller.ReadyToSend();
            Thread.Sleep(10);
            string payload = new string('c', 500);
            Clients.Caller.ReceivePayload(payload);
        }
@halter73 halter73 was assigned Oct 15, 2013
@DamianEdwards
SignalR member

Dupe of #2653

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