Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
Jeroen #1
Member since Oct 2017 · 4 posts
Group memberships: Members
Show profile · Link to this post
Subject: reconnect doesn't work
when i do an OnSubscribe, then I receive the error message 503.
No automatic reconnect will take place
Who knows how I can solve this?

  1. <iq xmlns="jabber:client" to="xx/ba50616d" xml:lang="en" type="error" from="xx" id="50793af2">
  2.    <request xmlns="xx" type="GET_COMPANY" />
  3.    <error type="cancel" code="503">
  4.       <service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
  5.    </error>
  6. </iq>
This post was edited on 2017-10-25, 19:55 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
please include the XML of the subscriütion request as well. Otherwise I cannot see what the error reply refers to.

Alex
Avatar
Jeroen #3
Member since Oct 2017 · 4 posts
Group memberships: Members
Show profile · Link to this post
I've done a bit more research and I think it has something to do with the way we auto reconnect. When the connection drops when we're doing maintenance, we want the application to automatically reconnect when the connection is back.

After a couple of retries we get a OnSocketError System.ObjectDisposedException

We can't get this to work.

  1. private XmppClientConnection _xmpp;
  2.  
  3. private void BindEvents()
  4. {
  5.     _xmpp.OnLogin += delegate
  6.     {
  7.         AddXmppLog("OnLogin", null);
  8.  
  9.     };
  10.  
  11.     _xmpp.OnReadXml += OnReadXml;
  12.  
  13.     _xmpp.OnAuthError += (sender, element) =>
  14.     {
  15.         AddXmppLog("OnAuthError", element.ToString());
  16.         Reconnect();
  17.     };
  18.     _xmpp.OnError += (sender, exception) =>
  19.     {
  20.         AddXmppLog("OnError", exception.ParseException());
  21.         Reconnect();
  22.     };
  23.     _xmpp.OnStreamError += (sender, element) =>
  24.     {
  25.         AddXmppLog("OnStreamError", element.ToString());
  26.         Reconnect();
  27.     };
  28.     _xmpp.OnSocketError += (sender, element) =>
  29.     {
  30.         AddXmppLog("OnSocketError", element.ToString());
  31.         Reconnect();
  32.     };
  33.     _xmpp.OnClose += sender =>
  34.     {
  35.         AddXmppLog("OnClose", sender.ToString());
  36.         Reconnect();
  37.     };
  38. }
  39.  
  40. private void UnbindEvents()
  41. {
  42.     _xmpp.OnLogin += null;
  43.     _xmpp.OnReadXml += null;
  44.     _xmpp.OnAuthError += null;
  45.     _xmpp.OnError += null;
  46.     _xmpp.OnStreamError += null;
  47.     _xmpp.OnSocketError += null;
  48.     _xmpp.OnClose += null;
  49. }
  50.  
  51. private XmppClientConnection GetConnection(Jid userJid, string resourceID)
  52. {
  53.     return new XmppClientConnection
  54.     {
  55.         Server = userJid.Server,
  56.         Username = userJid.User,
  57.         Password = GeneratedSettings.UserPassword,
  58.         AutoResolveConnectServer = true,
  59.         Resource = resourceID
  60.     };
  61. }
  62.  
  63.  
  64. public void Reconnect()
  65. {
  66.     AddXmppLog("Reconnect");
  67.  
  68.     Stop();
  69.  
  70.     _userJid.Resource = null;
  71.  
  72.     UnbindEvents();
  73.     _xmpp = null;
  74.    
  75.     _xmpp = GetConnection(_userJid, Guid.NewGuid().ToString("N").Substring(0, 8));
  76.     BindEvents();
  77.  
  78.     var timer = new Timer { Interval = 120000 };
  79.     timer.Elapsed += (sender, args) =>
  80.     {
  81.         timer.Stop();
  82.         timer = null;
  83.  
  84.         if (_reconnectRetryCount < 30)
  85.         {
  86.             _reconnectRetryCount++;
  87.         }
  88.         else
  89.         {
  90.             _reconnectRetryCount = 0;
  91.         }
  92.  
  93.         Start();
  94.     };
  95.     timer.Start();
  96. }
This post was edited on 2017-10-28, 10:59 by Alex.
Avatar
Alex #4
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Have you tried to debug agsXMPP, to see where this exception is coming from?
Or look at the stacktrace.

It may be better to unbind and bind your events in the timer function when you try to reconnect. Your code snippet does not seem to be complete, so it's hard for me to understand the complete logic behind it.

Alex
Avatar
Jeroen #5
Member since Oct 2017 · 4 posts
Group memberships: Members
Show profile · Link to this post
The exception happens, when we try to reconnect. It also looks like it's not a xmpp error

It happens after the Start function. The events in de DB look as follows:

- Start
- OnLogin
- OnSubscribe
<this is where the connection breaks in a maintenance window>
- OnClose
- Close
- Reconnect
- Start
- OnSocketError


  1. public class CallEvents
  2. {
  3.     private XmppClientConnection _xmpp;
  4.     private readonly IDictionary<string, Call> _calls = new Dictionary<string, Call>();
  5.     private IPersonRepository _personRepository;
  6.  
  7.     private int _reconnectRetryCount;
  8.     private readonly int[] _reconnectRetryIntervals = { 30000, 60000, 300000, 600000 };
  9.  
  10.     private Jid _userJid;
  11.     private string _logPath;
  12.     private int _organisationID;
  13.  
  14.     public void Init(IKernel kernel, RealtimeUserEventWebhookSetting settings)
  15.     {
  16.         ConsoleUtils.DebugMessage("CallEvents.Init");
  17.  
  18.         _userJid = new Jid(settings.UserJid);
  19.         var resourceID = Guid.NewGuid().ToString("N").Substring(0, 8);
  20.  
  21.         _personRepository = kernel.Get<IPersonRepository>();
  22.  
  23.         _organisationID = _personRepository.All().First(x => x.CompassUsername == _userJid.User).OrganisationID;
  24.  
  25.         _xmpp = new XmppClientConnection
  26.         {
  27.             Server = _userJid.Server,
  28.  
  29.             Username = _userJid.User,
  30.             Password = settings.Password,
  31.             AutoResolveConnectServer = true,
  32.             Resource = resourceID
  33.         };
  34.  
  35.         _xmpp.OnLogin += delegate
  36.          {
  37.              AddXmppLog("OnLogin", null);
  38.  
  39.              // update user with resource ID
  40.              _userJid.Resource = resourceID;
  41.  
  42.              var iq = new IQ(IqType.get, _userJid, new Jid("phone." + _userJid.Server))
  43.              {
  44.                  Id = Guid.NewGuid().ToString("N").Substring(0, 8),
  45.                  InnerXml = "<request type=\"GET_COMPANY\" xmlns=\"http://demo.com/compass\"/>"
  46.              };
  47.  
  48.              _xmpp.IqGrabber.SendIq(iq, (sender, iqresult, data) =>
  49.              {
  50.                  AddXmppLog("OnSubscribe", iqresult.ToString());
  51.  
  52.                  // current organisationID for user
  53.                  var organisationID = iqresult.FirstChild.SelectSingleElement("id").Value;
  54.  
  55.                  // subscribe to notifications
  56.                  var psm = new PubSubManager(_xmpp);
  57.                  psm.Subscribe(new Jid("pubsub." + _userJid.Server), _userJid, organisationID);
  58.              });
  59.          };
  60.  
  61.         _xmpp.OnReadXml += (sender, xmlString) =>
  62.         {
  63.             // parse string
  64.         };
  65.  
  66.         _xmpp.OnAuthError += (sender, element) =>
  67.         {
  68.             AddXmppLog("OnAuthError", element.ToString());
  69.             Reconnect();
  70.         };
  71.         _xmpp.OnError += (sender, exception) =>
  72.         {
  73.             AddXmppLog("OnError", exception.ParseException());
  74.             Reconnect();
  75.         };
  76.         _xmpp.OnStreamError += (sender, element) =>
  77.         {
  78.             AddXmppLog("OnStreamError", element.ToString());
  79.             Reconnect();
  80.         };
  81.         _xmpp.OnSocketError += (sender, element) =>
  82.         {
  83.             AddXmppLog("OnSocketError", element.ToString());
  84.             Reconnect();
  85.         };
  86.         _xmpp.OnClose += sender =>
  87.         {
  88.             AddXmppLog("OnClose", sender.ToString());
  89.             Reconnect();
  90.         };
  91.     }
  92.  
  93.     public void Start()
  94.     {
  95.         AddXmppLog("Start");
  96.         _xmpp.Open();
  97.     }
  98.  
  99.     public void Stop()
  100.     {
  101.         AddXmppLog("Close");
  102.         _xmpp.Close();
  103.     }
  104.  
  105.     public void Reconnect()
  106.     {
  107.         AddXmppLog("Reconnect");
  108.  
  109.         Stop();
  110.  
  111.         var timer = new Timer {Interval = _reconnectRetryIntervals[_reconnectRetryCount]};
  112.         timer.Elapsed += (sender, args) =>
  113.         {
  114.             timer.Stop();
  115.             timer = null;
  116.  
  117.             if (_reconnectRetryCount < _reconnectRetryIntervals.Length)
  118.             {
  119.                 _reconnectRetryCount++;
  120.             }
  121.             else
  122.             {
  123.                 _reconnectRetryCount = 0;
  124.             }
  125.            
  126.             Start();
  127.         };
  128.         timer.Start();
  129.     }
  130.  
  131.     public void AddXmppLog(string type, string text = null)
  132.     {
  133.         // add to db
  134.     }
  135. }
This post was edited on 2017-11-10, 11:24 by Alex.
Edit reason: fixed source code formating
Avatar
Alex #6
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
  • Have you tried to create a new XmppClientConnection instead of reusing it?
  • Have you debugged with the agsXMPP code to see whats happening?

I highly suggest to use the successors of agsXMPP which are MatriX and MatriX vNext. agsXMPP is not in active development since many years.
Avatar
Jeroen #7
Member since Oct 2017 · 4 posts
Group memberships: Members
Show profile · Link to this post
To check of the problem is solved in MatriX, can we get a trial license for 2 month ?
before we buy the license.
Avatar
Alex #8
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you can request as many trial licenses as you wish online.
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:
Forum: agsXMPP RSS