StackExchange.Redis icon indicating copy to clipboard operation
StackExchange.Redis copied to clipboard

suber is freeze.

Open FrenzyPig opened this issue 10 months ago • 3 comments
trafficstars

pub:

using System;
using StackExchange.Redis;

class Publisher
{
    static void Main()
    {
        ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("172.16.1.50");
        ISubscriber pub = redis.GetSubscriber();
        while (true)
        {
            pub.Publish(RedisChannel.Literal("channel1"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
        }
    }
}

sub:

using System;
using System.Threading;
using System.Threading.Tasks;
using StackExchange.Redis;

class Subscriber

{
    static int id = 0;
    //[System.Runtime.CompilerServices.MethodImpl(MethodImplOptions.NoOptimization)]
    static void Main()
    {
        ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("172.16.1.50");
        ISubscriber sub = redis.GetSubscriber();

        Task.Run(async () => await sub.SubscribeAsync(RedisChannel.Literal("channel1"), HandleMessage));

        while (true)
        {
            Thread.Sleep(1000);
        }
    }
    static void HandleMessage(RedisChannel channel, RedisValue message)
    {
        Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + $" id:{id++}  Received from {channel}: {message}");
    }
}

run in debug mode ,all fine! but run in release mode, after a while,the sub program is freeze. I add [System.Runtime.CompilerServices.MethodImpl(MethodImplOptions.NoOptimization)] to Main(),run fine. I dont know why... I need help,thx!

FrenzyPig avatar Jan 17 '25 23:01 FrenzyPig

Are you running the latest version 2.8.24 of StackExchange.Redis? Recent versions contain improvements for subscription connection resilience.

philon-msft avatar Jan 18 '25 16:01 philon-msft

yes ,use the latest version.

Image

FrenzyPig avatar Jan 20 '25 05:01 FrenzyPig

I'd advise taking a memory dump here to see what's happening, the best way to investigate what the freeze is would be to inspect the dump (Visual Studio is good for this, as I see in your screenshot used) and use the Debug > Windows > Threads view to see what they're stalled on.

NickCraver avatar Feb 18 '25 15:02 NickCraver