You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicasyncIAsyncEnumerable<UserDialogEventData>SubscribeForUserDialogEvents(CallContextcontext=default){varcancel=context.CancellationToken;varclientSubscription=newClientUserDialogSubscription();clientSubscriptions.Add(clientSubscription);logger.Info($"A subscriber for user dialog events connected. Current subscriber count {clientSubscriptions.Count}");vardelayCancellationTokenSource=CancellationTokenSource.CreateLinkedTokenSource(cancel);varwaitForCancellationTask=Task.Delay(Timeout.Infinite,delayCancellationTokenSource.Token);try{// Immediately push a success message so the client can verify the connection is up and running.yieldreturnnewUserDialogEventData{EventType=UserDialogEventType.ConfirmSuccess};//Push messages for all currently opened dialogsforeach(varopenDialogincurrentlyOpenedDialogs){yieldreturnopenDialog.Value;}varnextTcs=clientSubscription.UserDialogEventRequestBatch.NextBatch;while(!cancel.IsCancellationRequested){varnotificationTask=nextTcs.Task;varheartbeatTaskDelay=Task.Delay(2500,cancel);varcompletedTask=awaitTask.WhenAny(notificationTask,heartbeatTaskDelay,waitForCancellationTask);if(cancel.IsCancellationRequested){break;}if(completedTask==heartbeatTaskDelay){yieldreturnnewUserDialogEventData{EventType=UserDialogEventType.KeepAlive};continue;}varnotificationBatch=awaitnextTcs.Task;nextTcs=notificationBatch.NextBatch;//Send new event to clientyieldreturnnotificationBatch.UserDialogEventRequest;// Notify successfully sendclientSubscription.AcknowledgmentTcs.SetResult(true);}}finally{clientSubscriptions.Remove(clientSubscription);clientSubscription.AcknowledgmentTcs.SetResult(false);logger.Info("A subscriber for user dialog events disconnected");awaitdelayCancellationTokenSource.CancelAsync();waitForCancellationTask.Wait(TimeSpan.FromMilliseconds(100));delayCancellationTokenSource.Dispose();}}
this works fine for the most part and also when the client cleanly disconnects this works fine. This sends out new Data when triggered from another method and stops when the cancellation is requested. But we identified one problem here which is why we added the Keepalive messages all 2,5 seconds but that doesnt help.
The problem is that in the production environment our software runs in sometimes the connection is lost. (Most easily reproduced by just disconnecting the LAN Cable between client and server. In this case i would expect that in end up failing at on of the yield returns. However the yield returns just keep working and the loop things its still sending our data even after 10 Minutes it doesn't fail.
The client side pretty much immediately recognizes the connection loss but the server never does.
The most problematic for us is that we tried to monitor the send options to check if every connected client did receive the message. But in case of a connection loss we still think we can send out without an error but that isn't the case.
Obviosly there would be some Solutions here like using a two way stream with acknowledgement and timeout or similar things. But i would still like to know why the server doesnt recognize the connection loss. Is the code wrong? or is the server setup badly?
Im having a problem with server to client communication. I have a Server implementing the following interface method:
this works fine for the most part and also when the client cleanly disconnects this works fine. This sends out new Data when triggered from another method and stops when the cancellation is requested. But we identified one problem here which is why we added the Keepalive messages all 2,5 seconds but that doesnt help.
The problem is that in the production environment our software runs in sometimes the connection is lost. (Most easily reproduced by just disconnecting the LAN Cable between client and server. In this case i would expect that in end up failing at on of the yield returns. However the yield returns just keep working and the loop things its still sending our data even after 10 Minutes it doesn't fail.
The client side pretty much immediately recognizes the connection loss but the server never does.
The most problematic for us is that we tried to monitor the send options to check if every connected client did receive the message. But in case of a connection loss we still think we can send out without an error but that isn't the case.
Obviosly there would be some Solutions here like using a two way stream with acknowledgement and timeout or similar things. But i would still like to know why the server doesnt recognize the connection loss. Is the code wrong? or is the server setup badly?
Server setup:
The text was updated successfully, but these errors were encountered: