Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Avatar
ChrisGroh #1
Member since Nov 2017 · 1 post
Group memberships: Members
Show profile · Link to this post
Subject: Timing Issue with Setting Subscriptions
We're using MatriX to connect to Finesse and are experiencing an issue where some users intermittently get an error after logging in. Outside the intermittent error, everything seems to work fine.

The error is:

  1. <error code="400" type="wait" xmlns="jabber:client">
  2.    <unexpected-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
  3.    <not-subscribed xmlns="http://jabber.org/protocol/pubsub#errors" />
  4. </error>

And occurs if we make a call to PubSubManager.SubscribeAsync or PubSubManager.UnsubscribeAsync in the OnPresence event.


We were able to reproduce the issue with a simplified version of the code in a console app:

  1. static void Main(string[] args)
  2. {
  3.     using (client = new XmppClient())
  4.     {
  5.         client.SetXmppDomain(domain);
  6.         client.SetUsername(agentId);
  7.         client.Password = agentId;
  8.        
  9.         client.OnError += XmppClient_OnError;
  10.         client.OnPresence += Client_OnPresence;
  11.         client.Open();
  12.        
  13.         Console.WriteLine("Listening... Press any key to terminate");
  14.         Console.ReadKey();
  15.         client.Close();
  16.     }
  17. }
  18.  
  19. private static async void Client_OnPresence(object sender, PresenceEventArgs e)
  20. {
  21.     if (isSubscriptionsSet)
  22.         return;
  23.     isSubscriptionsSet = true;
  24.     try
  25.     {
  26.         var mgr = new PubsubSubscriptionManager(client, agentId);
  27.  
  28.         var subNodes = GetNodesToSubscribeTo();
  29.         await mgr.ConfigureInitialSubscriptions(subNodes.ToList());
  30.         Console.WriteLine("Subscriptions set");
  31.     }
  32.     catch (Exception ex)
  33.     {
  34.         Write(ex.ToString());
  35.         Console.WriteLine("Subscriptions set");
  36.     }
  37. }
  38.  
  39. internal class PubsubSubscriptionManager
  40. {
  41.     private readonly PubSubManager psManager;
  42.     private readonly Jid pubsubJid;
  43.     private readonly Jid userJid;
  44.  
  45.     public PubsubSubscriptionManager(XmppClient client, string agentId, ICtiEventLogger log)
  46.     {
  47.         psManager = new PubSubManager(client);
  48.         pubsubJid = new Jid("pubsub." + client.XmppDomain);
  49.         userJid = new Jid(agentId + "@" + client.XmppDomain);
  50.     }
  51.  
  52.     public async Task ConfigureInitialSubscriptions(List<FinesseNodePath> desiredSubscriptions)
  53.     {
  54.         var existingSubscriptions = await GetCurrentSubscriptions();
  55.         var missing = desiredSubscriptions.Except(existingSubscriptions);
  56.         var toRemove = existingSubscriptions.Except(desiredSubscriptions);
  57.  
  58.         foreach (var sub in toRemove)
  59.         {
  60.             var subResult = await psManager.UnsubscribeAsync(pubsubJid, sub.NodeId, userJid);
  61.             if (subResult.Type != IqType.Result)// Error occurs here
  62.             {
  63.                 throw new ApplicationException($"Subscription error for '{sub}': {subResult.Error}");
  64.             }
  65.         }
  66.         foreach (var sub in missing)
  67.         {
  68.             var subResult = await psManager.SubscribeAsync(pubsubJid, sub.NodeId, userJid);
  69.             if (subResult.Type != IqType.Result)// Error occurs here
  70.             {
  71.                 throw new ApplicationException($"Subscription error for '{sub}': {subResult.Error}");
  72.             }
  73.         }
  74.     }
  75.  
  76.     private async Task<List<FinesseNodePath>> GetCurrentSubscriptions()
  77.     {
  78.         var subResp = await psManager.RequestSubscriptionsAsync(pubsubJid, null);
  79.         if (subResp.Error != null)
  80.             throw new ApplicationException(subResp.Error.ToString());
  81.  
  82.         var pubSubData = subResp.Element<PubSub>();
  83.         var subList = pubSubData.Subscriptions.Elements<Subscription>();
  84.         var result = subList.Select(x => FinesseNodePath.FromPath(x.Node)).ToList();
  85.         return result;
  86.     }
  87. }
This post was edited 5 times, last on 2017-11-28, 21:49 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
it would help when you post your complete Xml log here. So that we can see exactly what you send to your server.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters: