SignalR (original) does not send messages to client - signalr
We're using SignalR (the original, not the Core version) and notice some inexplicable behavior. Our situation is as follows:
We have a Hub that accepts commands via a GenericCommand() method (see below).
These commands get placed on a messagebus using NServiceBus
The execution of the command yields an event
The handler of the event results in a message sent to all SignalR clients (see below)
Using the debugger tools in Chrome to view the Websocket messages it becomes clear that sometimes (but not always) the "InvokeToAll" message is never sent to any of the clients. No error is thrown and all clients that are connected just send their heartbeat signals indicating they are connected still.
Also, the tracing (see below) logs on the server indicate that the connection is clearly active the whole time, but for some reason the three test "Received" messages that are sent immediately from the hub are sent back to the clients, but the resulting "InvokeToAll" sent from the event handler are for some reason not sent using the Websocket. We know the event handler is called because the _notificationService.MarkAsDone() call leaves traces in the database confirming it's called.
One final thing we've noticed is that this setup works and works until it doesn't. As soon as the messages stop being sent to the clients, it stops for all clients at all time. We're completely at a loss as to what could possibly be happening or what else we can do to further debug this. No errors are thrown and something that works just suddenly stops working without notice...
Any help or pointers would be greatly appreciated.
Here's the code for the Hub (step 1):
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");
}
And here's the code for the event handler (step 4)
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);
}
Here's an excerpt from the trace log on the server for the connection of this client:
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)
As it turns out, this problem was caused by the fact that we have multiple sites in the same application pool pointed at the same directory using different host names.
This caused the application to run multiple concurrent instances of this site despite only showing one w3wp.exe process (which is what we looked at to dismiss the possibility of multiple instances running at once).
We plan to change this situation by simply combining the bindings to the same website instance when we have the opportunity. I fully expected the problem to be solved then.
Related
SockJS connections will be closed when multiple connections open
If only one SockJS (polling XHR) connection is open, then the app works fine. As soon as I additionally open it in a new window, then the connections will periodically be closed. The client is SockJS client, the backend is Spring Boot with MVC and SockJS enabled. This is what I see on the server side: 2022-03-14 10:40:20.992 DEBUG 752 --- [nio-8311-exec-7] a.w.b.u.d.websocket.WebSocketHandler : connection opened, id: gqgmlrff 2022-03-14 10:40:21.015 DEBUG 752 --- [nio-8311-exec-9] a.w.b.u.d.websocket.WebSocketHandler : Server received message: {"action":"subscribe","payload":{"id":"c910f5d1-9e16-4e30-9559-e0e27973177b","entityType":"PROJEKT"}} after 15-20 seconds 2022-03-14 10:40:40.075 DEBUG 752 --- [ SockJS-10] a.w.b.u.d.websocket.WebSocketHandler : connection closed, sessionId: gqgmlrff, status: CloseStatus[code=3000, reason=Go away!] This repeats infinitely with sessions of both windows. It seems that the session closing will be initiated by the backend, since on client side the .onclose() handler will be executed.
The reason was that for both app instances different auth tokens have been generated and the equality wasn't updated. After updating equals() and hashCode() as follow the requests were correctly processed. override fun equals(obj: Any?): Boolean = obj is KeycloakToken && principal == obj.principal && authorities == obj.authorities && isAuthenticated == obj.isAuthenticated override fun hashCode(): Int { var code = 31 for (authority in authorities) { code = code xor authority.hashCode() } code = code xor principal.hashCode() if (this.isAuthenticated) { code = code xor -37 } return code }
OneSignal does not showing notification when app is in foreground
I entegrated my flutter app with onesignal, and it's working perfect when app is in background, but in foreground it's receiving notification but not showing it any idea why? log flutter: OSNotificationReceivedEvent complete with notification: Instance of 'OSNotification' VERBOSE: finishProcessingNotification: Fired! VERBOSE: Notification display type: 7 VERBOSE: notificationReceived called! opened: NO VERBOSE: finishProcessingNotification: call completionHandler with options: 7 Foreground handler OneSignal.shared.setNotificationWillShowInForegroundHandler( (OSNotificationReceivedEvent event) { event.complete(event.notification); });
I've removed the answer because I think it is just copy paste
Saving an entity with EF and dispatching a message to the client with SignalR in the same method
I have a problem with WebSocket being disconnected while trying to firstly save entity to the database with EF Core, then to dispatch a message to the clients using SignalR Core. Everything works perfectly when I separate these two operations, one with AJAX call to the controller's action, to save entity to the database, one with hub method for dispatching messages to the clients. But I want to ensure that the entity is successfully saved, then to be dispatched. When I try to merge saving entity and dispatching a message to the clients into the same hub method or controller's action (with dependency injection), I've got the errors which could be found down bellow (with log level - trace). 00:51:03.876 [2020-01-04T23:51:03.877Z] Trace: (WebSockets transport) sending data. String data of length 307. Utils.ts:178:39 00:51:04.147 [2020-01-04T23:51:04.148Z] Trace: (WebSockets transport) socket closed. Utils.ts:178:39 00:51:04.148 [2020-01-04T23:51:04.148Z] Debug: HttpConnection.stopConnection(undefined) called while in state Connected. Utils.ts:178:39 00:51:04.148 [2020-01-04T23:51:04.149Z] Information: Connection disconnected. Utils.ts:174:39 00:51:04.149 [2020-01-04T23:51:04.149Z] Debug: HubConnection.connectionClosed(undefined) called while in state Connected. Utils.ts:178:39 00:51:04.149 [2020-01-04T23:51:04.149Z] Information: Connection reconnecting. Utils.ts:174:39 00:51:04.150 [2020-01-04T23:51:04.150Z] Information: Reconnect attempt number 1 will start in 0 ms. Utils.ts:174:39 00:51:04.150 Chat - Error: Invocation canceled due to the underlying connection being closed. conversation line 2 > scriptElement:27:36 00:51:04.153 [2020-01-04T23:51:04.153Z] Debug: Starting connection with transfer format 'Text'. Utils.ts:178:39 00:51:04.154 [2020-01-04T23:51:04.154Z] Debug: Sending negotiation request: http://localhost:11597/chatHub/negotiate?negotiateVersion=1. Utils.ts:178:39 00:51:04.168 [2020-01-04T23:51:04.169Z] Debug: Selecting transport 'WebSockets'. Utils.ts:178:39 00:51:04.168 [2020-01-04T23:51:04.169Z] Trace: (WebSockets transport) Connecting. Utils.ts:178:39 00:51:04.179 [2020-01-04T23:51:04.180Z] Information: WebSocket connected to ws://localhost:11597/chatHub?id=Amf9CsFZQfnR8-3PoGr8HQ. Utils.ts:174:39 00:51:04.179 [2020-01-04T23:51:04.180Z] Debug: The HttpConnection connected successfully. Utils.ts:178:39 00:51:04.180 [2020-01-04T23:51:04.180Z] Debug: Sending handshake request. Utils.ts:178:39 00:51:04.180 [2020-01-04T23:51:04.181Z] Debug: Hub handshake failed with error 'WebSocket is not in the OPEN state' during start(). Stopping HubConnection. Utils.ts:178:39 00:51:04.181 [2020-01-04T23:51:04.181Z] Trace: (WebSockets transport) socket closed. Utils.ts:178:39 00:51:04.181 [2020-01-04T23:51:04.182Z] Debug: HttpConnection.stopConnection(undefined) called while in state Disconnecting. Utils.ts:178:39 00:51:04.182 [2020-01-04T23:51:04.182Z] Error: Connection disconnected with error 'WebSocket is not in the OPEN state'. Utils.ts:168:39 00:51:04.183 [2020-01-04T23:51:04.184Z] Debug: HubConnection.connectionClosed(WebSocket is not in the OPEN state) called while in state Reconnecting. Utils.ts:178:39 00:51:04.183 [2020-01-04T23:51:04.184Z] Information: Reconnect attempt failed because of error 'WebSocket is not in the OPEN state'. Utils.ts:174:39 00:51:04.184 [2020-01-04T23:51:04.185Z] Information: Reconnect attempt number 2 will start in 2000 ms. Utils.ts:174:39 Here is hub method: public async Task SendMessage(Message message) { // Eager loading conversation with matching Id var chat = _context.Chat .Include(c => c.PersonA) .Include(c => c.PersonB) .FirstOrDefault(m => m.Id == message.ChatId); /* * I'm doing a few validations here */ // Saving entity to the database await _context.AddAsync(new Message { SenderId = message.SenderId, ChatId = message.ChatId, Text = message.Text }); await _context.SaveChangesAsync(); // Dispatching message to the clients using strongly-typed hub var usersId = new List<string> { chat.PersonAId, chat.PersonBId }; await Clients .Users(usersId) .ReceiveMessage(message); } The potential problem could lie in timing, the dispatching can't wait for the EF to execute all operations, because when I just load the conversation It works good, adding more complexity, it breaks down.
Error while retrieving an encrypted message
I am using ejabberd 15.11. While a client is trying to retrieve message from archive getting below error in error logs. My client is sending and receiving encrypted messages Error log: [error] <0.2337.0>#gen_iq_handler:process_iq:128 { {badmatch,{error,{4,<<"not well-formed (invalid token)">>}}}, [ {mod_mam,'-select/8-fun-4-',3,[{file,"src/mod_mam.erl"},{line,681}]}, {lists,map,2,[{file,"lists.erl"},{line,1237}]}, {mod_mam,select,8,[{file,"src/mod_mam.erl"},{line,677}]}, {mod_mam,select_and_send,10,[{file,"src/mod_mam.erl"},{line,577}]}, {gen_iq_handler,process_iq,6,[{file,"src/gen_iq_handler.erl"},{line,127}]}, {gen_iq_handler,handle_info,2,[{file,"src/gen_iq_handler.erl"},{line,171}]}, {gen_server,try_dispatch,4,[{file,"gen_server.erl"},{line,593}]}, {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,659}]} ] }
crypto:block_encrypt(Type, Key, Ivec, PlainText)is not working insted of it try to use crypto:aes_cfb_128_encrypt(Key, Ivec, PlainText) function.
"Access violation reading location" in IISExpress 10 (in webengine4.dll) with Selenium IEDriver 12.6
My configuration as follows. XUnit runner (1.9.2) fires tests generated using SpecFlow. IISExpress 10 starts in singleton like this: _iisProcess = new Process { StartInfo = { FileName = Path.Combine(programFiles, #"IIS Express\iisexpress.exe") } }; var applicationPath = GetApplicationPath(); _iisProcess.StartInfo.Arguments = string.Format( "/path:{0} /port:{1} /systray:false /trace:e", applicationPath, IisPort); // so far 9090 _iisProcess.Start(); Selenium IEDriverServer.exe (2.46) configured as this: _driver = new InternetExplorerDriver( new InternetExplorerOptions(){EnsureCleanSession = true}); The machine configured as per this guide. IEDriverServer.exe listens 17923 port. At some points in tests IISExpress fails with "Access violation" (c0000005) error. The actual fail system test varies but looks like it happens when there is some active UI interaction. There is SignalR, dynamic content and other. The Problem signature: Problem Event Name: APPCRASH Application Name: iisexpress.exe Application Version: 10.0.10046.0 Application Timestamp: 55121079 Fault Module Name: webengine4.dll Fault Module Version: 4.6.57.0 Fault Module Timestamp: 551b8b21 Exception Code: c0000005 Exception Offset: 00066ccf OS Version: 6.3.9600.2.0.0.256.48 Locale ID: 1049 Additional Information 1: 5861 Additional Information 2: 5861822e1919d7c014bbb064c64908b2 Additional Information 3: a10f Additional Information 4: a10ff7d2bb2516fdc753f9c34fc3b069 Sometimes it fails at code like this with "OpenQA.Selenium.WebDriverTimeoutException : Timed out after 30 seconds" at DefaultWait.Until IWait<IWebDriver> wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30.00)); try { wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete")); } catch (InvalidOperationException ex) // js error { /*...*/ } IISExpress log also does not help. It writes some last requests only and terminates: Request started: "POST" http://localhost:9090/signalr/abort?transport=webSockets... Request ended: http://localhost:9090/signalr/connect?transport=webSockets... with HTTP status 101.0 Request ended: http://localhost:9090/signalr/abort?transport=webSockets&clientProtocol=1.4.... with HTTP status 200.0 WriteCompletedInline Action = 00000002 Action = 00000000 Request ended: http://localhost:9090/signalr/connect?transport=webSockets.... with HTTP status 101.0 Request ended: http://localhost:9090/BotDetectCaptcha.ashx?get=image&c=SampleCaptcha&t=44c45e60afac46809bfce16e123b54a2 with HTTP status 200.0 It does not help if the tests run under Administrator. The same when R# test runner fires the tests. Any your thoughts, help would be much appreciated. Thanks!
In case it would be helpful someone it helped me to solve the problem by the reinstallation of IIS Express. IIS Express 8.0 MSI file could be found at here.