我们正在使用SignalR(原始版本,而不是Core版本),请注意某些莫名其妙的行为。我们的情况如下:
使用Chrome中的调试器工具查看Websocket消息,很明显,有时(但并非总是)“ InvokeToAll”消息从未发送给任何客户端。不会引发任何错误,并且所有连接的客户端仅发送其心跳信号,表明它们仍在连接。
此外,服务器上的跟踪日志(请参阅下文)表明该连接在整个时间内都处于活动状态,但是由于某种原因,从集线器立即发送的三个测试“已接收”消息被发送回客户端,但是从事件处理程序发送的结果“ InvokeToAll”由于某种原因未使用Websocket发送。我们知道事件处理程序已被调用,因为_notificationService.MarkAsDone()
调用会在数据库中留下跟踪以确认其被调用。
我们注意到的最后一件事是,此设置有效,直到无效为止。一旦消息停止发送给客户端,它就会一直对所有客户端停止。对于可能发生的事情或者我们可以做进一步调试的事情,我们完全不知所措。没有引发任何错误,并且某些工作突然停止而没有通知...
任何帮助或指针,将不胜感激。
public async Task GenericCommand(GenericEventData data) {
await _messageBus.PublishEvent(new GenericSignalrCommandReceivedEvent {
CorrelationId = Guid.Parse(data.CorrelationId),
Command = data.Command,
DataJson = data.DataJson,
ConnectionId = Context.ConnectionId
});
// Added for debugging purposes
var ctx = GlobalHost.ConnectionManager.GetHubContext<EventHub>();
IClientProxy proxy = ctx.Clients.Client(Context.ConnectionId);
await proxy.Invoke(data.CorrelationId, "Received - ConnectionId");
proxy = ctx.Clients.User(Context.User.Identity.Name);
await proxy.Invoke(data.CorrelationId, "Received - Clients.User");
proxy = ctx.Clients.Group("JCUSER:" + Context.User.Identity.Name);
await proxy.Invoke(data.CorrelationId, "Received - Clients.Group");
}
private async Task ReplyViaSignalR(SignalrCompletedData data, IMessageHandlerContext context) {
var ctx = GlobalHost.ConnectionManager.GetHubContext<EventHub>();
var proxy = ctx.Clients.All;
await proxy.Invoke("InvokeToAll", "Yay message received!");
await _notificationService.MarkAsDone(data);
}
SignalR.Transports.TransportHeartBeat Information: 0 : Connection 1d603a67-1161-4a27-82f0-9046ec73cd60 is New.
SignalR.Transports.WebSocketTransport Verbose: 0 : Sending outgoing message. Connection id: 1d603a67-1161-4a27-82f0-9046ec73cd60, transport: WebSocketTransport, message: {"C":"d-498F7600-B,15|rS,0|pP,A|rT,1","S":1,"M":[]}
SignalR.Transports.WebSocketTransport Verbose: 0 : Sending outgoing message. Connection id: 1d603a67-1161-4a27-82f0-9046ec73cd60, transport: WebSocketTransport, message: {"C":"d-498F7600-B,15|rS,0|pP,A|rT,2|pR,1E","G":"F2q+KKxufchVxQUnH9leeyYR6fGPfHYRCIQW55XZbNEbbibRlbVYld/b0fzihC34VrDwmoaNy2uTJYnRCeQO9zGEoqNk+9qbAi72dPep52CgpicyPGQOlvNzUOlNK1v2j34SdPXHI8DwpDwx/7SA317XJMJPxrCE5Qsgt/kgTzE=","M":[]}
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)
SignalR.Transports.WebSocketTransport Verbose: 0 : Sending outgoing message. Connection id: 1d603a67-1161-4a27-82f0-9046ec73cd60, transport: WebSocketTransport, message: {"C":"d-498F7600-B,1F|rS,5|pP,19|rT,2|pR,43","M":[{"H":"EventHub","M":"a1ec2fa6-f33c-4161-9166-07ee64558be1","A":["Received - ConnectionId"]},{"H":"EventHub","M":"a1ec2fa6-f33c-4161-9166-07ee64558be1","A":["Received - Clients.User"]}]}
SignalR.Transports.WebSocketTransport Verbose: 0 : Sending outgoing message. Connection id: 1d603a67-1161-4a27-82f0-9046ec73cd60, transport: WebSocketTransport, message: {"C":"d-498F7600-B,1F|rS,5|pP,19|rT,2|pR,44","M":[{"H":"EventHub","M":"a1ec2fa6-f33c-4161-9166-07ee64558be1","A":["Received - Clients.Group"]}]}
SignalR.Transports.WebSocketTransport Verbose: 0 : Sending outgoing message. Connection id: 1d603a67-1161-4a27-82f0-9046ec73cd60, transport: WebSocketTransport, message: {"I":"4"}
SignalR.Transports.WebSocketTransport Verbose: 0 : Sending outgoing message. Connection id: 1d603a67-1161-4a27-82f0-9046ec73cd60, transport: WebSocketTransport, message: {"C":"d-498F7600-B,1F|rS,5|pP,19|rT,2|pR,45","M":[]}
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)
事实证明,此问题是由以下事实引起的:我们在同一应用程序池中有多个站点使用不同的主机名指向同一目录。
尽管仅显示了一个w3wp.exe进程(这使我们避免了多个实例一次运行的可能性,但是这使该应用程序运行了该站点的多个并发实例。
我们计划通过在有机会的情况下简单地将绑定合并到同一网站实例来改变这种情况。我完全希望这个问题能够解决。