Skip to content

Commit

Permalink
debug Subscrible 多端断网
Browse files Browse the repository at this point in the history
  • Loading branch information
28810 authored and 28810 committed Dec 19, 2019
1 parent d5b6350 commit 513d774
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/CSRedisClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,7 @@ private void Subscribe(object state)
var subscr = ((string[] chans, Object<RedisClient> conn))state;
var pool = subscr.conn.Pool as RedisClientPool;
var testCSRedis_Subscribe_Keepalive = "0\r\n";// $"CSRedis_Subscribe_Keepalive{Guid.NewGuid().ToString()}";
var testKeepalived = true;

EventHandler<RedisSubscriptionReceivedEventArgs> SubscriptionReceived = (a, b) =>
{
Expand All @@ -1500,6 +1501,10 @@ private void Subscribe(object state)
Body = b.Message.Body,
Channel = b.Message.Channel
});
else
{
testKeepalived = true;
}
}
}
catch (Exception ex)
Expand All @@ -1525,13 +1530,22 @@ private void Subscribe(object state)
{
foreach (var chan in subscr.chans)
{
if (Redis.PublishNoneMessageId(chan, testCSRedis_Subscribe_Keepalive) <= 0)
testKeepalived = false;
Redis.PublishNoneMessageId(chan, testCSRedis_Subscribe_Keepalive);
for (var a = 0; a < 50; a++)
{
if (isSubscribeing == false) return;
Thread.CurrentThread.Join(100);
if (testKeepalived) break;
}
if (testKeepalived == false)
{
isKeepliveReSubscribe = true;
//订阅掉线,重新订阅
try { subscr.conn.Value.Unsubscribe(); } catch { }
try { subscr.conn.Value.Quit(); } catch { }
try { subscr.conn.Value.Socket?.Shutdown(System.Net.Sockets.SocketShutdown.Both); } catch { }
break;
}
}
}
Expand Down

0 comments on commit 513d774

Please sign in to comment.