关闭websocket时出现SignalR错误 - 无效句柄

问题描述 投票:6回答:1

出现SignalR问题:

关闭websocket时出错:System.Net.WebSockets.WebSocketException(0x80070006):句柄无效

我认为问题与此代码有关:

var currentHub = GlobalHost.ConnectionManager.GetHubContext<HubManager>();
currentHub.Groups.Remove(userConnectionId, roomName);

怎么修好?

c# exception websocket signalr
1个回答
1
投票

我遇到了同样的问题,当我向SignalR添加一个SQL Backplane时,这种情况开始发生了

它与集线器环境的“新鲜度”有关,我所做的是:

    /// <summary>
    /// In case a backplane  is used (in case of load balancer) , the instance should always be taken fresh
    /// if no backplane is used no need to refresh the instance on each invocation
    public class HubContextService 
    {
        bool BackplaneUsed { get; set; }
        IHubContext _context = null;

        public  HubContextService(bool isBackPlaneUsed = true)
        {
            BackplaneUsed = isBackPlaneUsed;
        }

        public IHubContext HubContext
        { 
            get
            {
                if (BackplaneUsed)
                {
                    return GlobalHost.ConnectionManager.GetHubContext<HubManager>();
                }
                else
                {
                    if (_context == null)
                    {
                        _context = GlobalHost.ConnectionManager.GetHubContext<HubManager>(); 
                    }
                    return _context;
                }
            }
            set 
            {
                _context = value;
            }
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.